先上圖:
ListView的布局文件listview.xml
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent">
- <ImageView android:id="@+id/tv_touxiang"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:src="@drawable/touxiang"
- android:layout_margin="5px"/>
- <LinearLayout android:orientation="vertical"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content">
- <TextView android:id="@+id/tv_nick"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="18px" />
- <TextView android:id="@+id/tv_origtext"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="14px" />
- </LinearLayout>
- </LinearLayout>
在Activity中使用:
- public class HomeActivity extends Activity {
- private ListView listView;
- private List<Map<String,String>> data = new ArrayList<Map<String,String>>();
- AnalyticData analyticData=new AnalyticData();
-
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.home_activity);
- listView=(ListView) findViewById(R.id.listview);
- Map<String, String> map = new HashMap<String, String>();
- map.put("nick","張三");
- map.put("origtext","張三發(fā)了一條微博,哈哈");
- data.add(map);
- Map<String, String> map2 = new HashMap<String, String>();
- map2.put("nick","李四");
- map2.put("origtext", "李四發(fā)了一條微博,哈哈");
- data.add(map2);
- SimpleAdapter adapter=new SimpleAdapter(
- this,
- data,
- R.layout.listview,
- new String[]{"nick","origtext"},
- new int[]{R.id.tv_nick,R.id.tv_origtext}
- );
- listView.setAdapter(adapter);
- }
該文章在 2013/2/25 14:37:14 編輯過(guò)