Android 自定义 ListView
				
									
					
					
						|  | 
							admin 2013年2月25日 14:37
								本文热度 5289 | 
					
				 
				先上图:

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","张三发了一条微博,哈哈");  
-         data.add(map);  
-         Map<String, String> map2 = new HashMap<String, String>();  
-         map2.put("nick","李四");  
-         map2.put("origtext", "李四发了一条微博,哈哈");  
-         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 编辑过