<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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/tv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
private static String[] names= {"功能1","功能2","功能3","功能4","功能5"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv = (ListView) findViewById(R.id.lv);
lv.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item,R.id.tv, names));
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv = (ListView) findViewById(R.id.lv);
List<Map<String,Object>> data = new ArrayList<Map<String,Object>>();
Map<String,Object> map1 = new HashMap<String, Object>();
map1.put("nameText", "第1个啦啦啦");
map1.put("icon", R.drawable.ic_launcher);
Map<String,Object> map2 = new HashMap<String, Object>();
map2.put("nameText", "第2个啦啦啦");
map2.put("icon", R.drawable.info_buse);
Map<String,Object> map3 = new HashMap<String, Object>();
map3.put("nameText", "第3个啦啦啦");
map3.put("icon", R.drawable.info_duijiao);
Map<String,Object> map4 = new HashMap<String, Object>();
map4.put("nameText", "第4个啦啦啦");
map4.put("icon", R.drawable.info_flash);
data.add(map1);
data.add(map2);
data.add(map3);
data.add(map4);
lv.setAdapter(new SimpleAdapter(this, data, R.layout.list_item, new String[]{"nameText", "icon"},new int[]{R.id.tv,R.id.iv}));
}