常见数据适配器
-
ArrayAdapter 数组适配器
java代码:(要记得声明ListView控件) String[] objects = new String[]{"app","context","Media","nfc","os"} lv.setAdapter(new ArrayAdapter<String>(this,R.layout.item,objects)); Android代码: <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="20dp" android:textColor="#66ff0000" > </TextView>
-
SimpleAdapter 简单数据适配器
java代码:(要记得声明ListView控件) List<Map<String,Object>> data= new ArrayList<Map<String,Object>>(); Map<String,Object> map1 = new HashMap<String, Object>(); map1.put("icon",R.drawable.ic_launcher); map1.put("name", "功能设置"); data.add(map1); Map<String,Object> map2 = new HashMap<String, Object>(); map2.put("icon",R.drawable.ic_tupian); map2.put("name", "qita设置"); data.add(map2); lv.setAdapter(newSimpleAdapter(this,data,R.layout.item, new String[]{"icon","name"}, new int[]{R.id.iv,R.id.tv})); Android代码: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <ImageView android:id="@+id/iv" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/tv" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <LinearLayout/>
网友评论