标签:代码实现 java ted highlight ini activity rap find auto
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"> <ListView android:id="@+id/lv" android:layout_width="match_parent" android:layout_height="wrap_content" /> </android.support.constraint.ConstraintLayout>
class myAdapter extends BaseAdapter { @Override public int getCount() { return 110; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { /*TextView textView = new TextView(MainActivity.this); textView.setText("天道酬勤"); return textView;*/ TextView textview; if (convertView == null) { textview = new TextView(MainActivity.this); } else { textview = (TextView) convertView; } textview.setText("天道酬勤"); return textview; } }
Madapter madapter = new Madapter(); //listView.setAdapter(madapter);
class myAdapter extends BaseAdapter { @Override public int getCount() { return 110; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { /*TextView textView = new TextView(MainActivity.this); textView.setText("天道酬勤"); return textView;*/ TextView textview; if (convertView == null) { textview = new TextView(MainActivity.this); } else { textview = (TextView) convertView; } textview.setText("天道酬勤"); return textview; } }
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/iv" android:layout_width="100dp" android:layout_height="100dp" android:src="@mipmap/ic_launcher" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toRightOf="@id/iv" android:orientation="vertical"> <TextView android:id="@+id/tv1" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" android:text="恐怖墙" android:textColor="@android:color/black" android:textSize="24sp" /> <TextView android:id="@+id/tv2" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" android:text="恐怖墙" /> </LinearLayout> </RelativeLayout>
View view = View.inflate(MainActivity.this, R.layout.item, null);
view = View.inflate(MainActivity.this, R.layout.item, null);
view = LayoutInflater.from(MainActivity.this).inflate(R.layout.item,null);
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE); view = layoutInflater.inflate(R.layout.item,null);
<ListView android:id="@+id/lv" android:layout_width="match_parent" android:layout_height="wrap_content" />
My my = new My(this); SQLiteDatabase db = my.getWritableDatabase();//my.onCreate(db); ContentValues values = new ContentValues(); values.put("name", "zhangsan"); values.put("phone", 110); db.insert("info", null, values); mList = new ArrayList<>(); Cursor cursor = db.query("info", null, null, null, null, null, null); while (cursor.moveToNext()) { Person person = new Person(); Log.d(TAG, "onCreate: 有数据"); String name = cursor.getString(1); int phone = cursor.getInt(2); person.setName(name); person.setPhone(phone); mList.add(person); } mLv.setAdapter(new myAdapter());
class myAdapter extends BaseAdapter { @Override public int getCount() { return mList.size(); } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return 0; } @Override public View getView(int position, View convertView, ViewGroup parent) { if (convertView == null) { convertView = View.inflate(MainActivity.this, R.layout.item, null); } Person person = mList.get(position); TextView tv = convertView.findViewById(R.id.tv); TextView tv1 = convertView.findViewById(R.id.tv1); tv.setText(person.getName()); tv1.setText(person.getPhone() + ""); return convertView; } }
String[] menu = new String[]{"android", "java", "c", "c++", "html", "mysql"}; private ListView mListView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mListView = findViewById(R.id.lv); init(); myAdapter myAdapter = new myAdapter(); Madapter madapter = new Madapter(); //mListView.setAdapter(madapter); mListView.setAdapter(new ArrayAdapter<String>(this,R.layout.item,R.id.tv1,menu)); }
标签:代码实现 java ted highlight ini activity rap find auto
原文地址:https://www.cnblogs.com/nangongyibin/p/10211654.html