2012年10月4日 星期四

android ListView 介紹與使用



FROM

http://blog.joomla.org.tw/android/178-ListV*******

http://rayleung.iteye.com/blog/540423

http://www.vogella.com/articles/AndroidListView/article.html

http://hi.baidu.com/ljlkings/item/afb3b4c2b2a96e66f7c95dac







常用的的這些樣式如下所列:
android.R.layout.simple_list_item_1:一行text
android.R.layout.simple_list_item_2:一行text較大,一行text較小
android.R.layout.simple_list_item_single_choice:單選
android.R.layout.simple_list_item_multiple_choice:多選按鈕
android.R.layout.simple_list_item_checked:勾選盒



public class ListDemo3 extends ListActivity {
 /** Called when the activity is first created. */
 ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
 private SimpleAdapter adapter;

 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);

 //把資料加入ArrayList中
 for(int i=0; i<mPlaces.length; i++){
 HashMap<String,String> item = new HashMap<String,String>();
 item.put( "food", mFoods[i]);
 item.put( "place",mPlaces[i] );
 list.add( item );
 }

 //新增SimpleAdapter
 adapter = new SimpleAdapter(
 this,
 list,
 android.R.layout.simple_list_item_2,
 new String[] { "food","place" },
 new int[] { android.R.id.text1, android.R.id.text2 } );

 //ListActivity設定adapter
 setListAdapter( adapter );

 //啟用按鍵過濾功能,這兩行資料都會進行過濾
 getListView().setTextFilterEnabled(true);
 }

 private static final String[] mPlaces = new String[] {
 "台北市", "新北市", "台南市", "高雄市", "苗粟縣",
 "台北市", "新北市", "台南市", "高雄市", "苗粟縣",
 "台北市", "新北市", "台南市", "高雄市", "苗粟縣",
 "台北市", "新北市", "台南市", "高雄市", "苗粟縣",
 "台北市", "新北市", "台南市", "高雄市", "苗粟縣",
 "台北市", "新北市", "789", "cde", "abc"
 };

 private static final String[] mFoods = new String[] {
 "大餅包小餅", "蚵仔煎", "東山鴨頭", "臭豆腐", "潤餅",
 "豆花", "青蛙下蛋","豬血糕", "大腸包小腸", "鹹水雞",
 "烤香腸","車輪餅","珍珠奶茶","鹹酥雞","大熱狗",
 "炸雞排","山豬肉","花生冰","剉冰","水果冰",
 "包心粉圓","排骨酥","沙茶魷魚","章魚燒","度小月",
 "aaa","abc","bbb","bcd","123"
 };
}

0 意見:

張貼留言

 

MangoHost Copyright © 2009 Cookiez is Designed by Ipietoon for Free Blogger Template