多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內(nèi)最全I(xiàn)T社區(qū)平臺(tái) 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php開源 > 綜合技術(shù) > 一起學(xué)android之SimpleAdapter使用(13)

一起學(xué)android之SimpleAdapter使用(13)

來源:程序員人生   發(fā)布時(shí)間:2015-01-06 08:07:42 閱讀次數(shù):2541次

SimpleAdapter:將List集合的多個(gè)對(duì)象包裝成列表項(xiàng)。

我們可以通過SimpleAdapter來實(shí)現(xiàn)1些復(fù)雜的列表,請(qǐng)看以下實(shí)例:


simpleadapter_list布局文件:

<span style="font-size:18px;"><?xml version="1.0" encoding="utf⑻"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ListView android:id="@+id/lv_simpleadapter" android:layout_width="fill_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout></span>

simpleadapter布局文件:用于顯示列表項(xiàng)的組件

<span style="font-size:18px;"><?xml version="1.0" encoding="utf⑻"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/ll_top" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="horizontal"> <ImageView android:id="@+id/iv_image" android:layout_height="wrap_content" android:layout_width="wrap_content" android:scaleType="fitXY" android:src="@drawable/a5i" android:layout_gravity="center"/> <LinearLayout android:id="@+id/ll_right" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_marginTop="4dp"> <TextView android:id="@+id/tv_title" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="20sp" android:text="AS"/> <TextView android:id="@+id/tv_des" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="13sp" android:text="AS" /> </LinearLayout> </LinearLayout> </RelativeLayout></span>

SimpleAdapterTest主文件:

<span style="font-size:18px;">public class SimpleAdapterTest extends Activity { int[] images = new int[] { R.drawable.a5i, R.drawable.a5j, R.drawable.a5k }; String[] titles = new String[] { "電話", "QQ", "聯(lián)系人" }; String[] des = new String[] { "當(dāng)前無電話記錄", "當(dāng)前無QQ聊天記錄", "最近無聯(lián)系人" }; private ListView lv_simple; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simpleadapter_list); initView(); setData(); } private void initView() { lv_simple = (ListView) findViewById(R.id.lv_simpleadapter); lv_simple.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Toast.makeText(SimpleAdapterTest.this, titles[position], Toast.LENGTH_SHORT).show(); } }); } private void setData() { // 創(chuàng)建數(shù)據(jù)源 List<HashMap<String, Object>> listItems = new ArrayList<HashMap<String, Object>>(); for (int i = 0; i < titles.length; i++) { // 每一個(gè)列表項(xiàng)的內(nèi)容 HashMap<String, Object> listItem = new HashMap<String, Object>(); listItem.put("image", images[i]); listItem.put("title", titles[i]); listItem.put("desc", des[i]); listItems.add(listItem); } /* * SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) * 參數(shù)說明: * context:全部利用的上下文。 * data:是List<? extends Map<String, ?>>的集合對(duì)象,其中每一個(gè)Map<String, ?>代表每列的列表項(xiàng)內(nèi)容。 * resource:界面布局文件的ID。 * from:String[]類型的參數(shù),指定了Map<String, ?>中的每一個(gè)key對(duì)應(yīng)的value來生成列表項(xiàng)。 * to:int[]類型的參數(shù),顯示每一個(gè)列表項(xiàng)顯示的組件。 */ SimpleAdapter simpleAdapter = new SimpleAdapter(SimpleAdapterTest.this, listItems, R.layout.simpleadapter, new String[] { "image", "title", "desc" }, new int[] { R.id.iv_image, R.id.tv_title, R.id.tv_des }); //綁定適配器 lv_simple.setAdapter(simpleAdapter); } }</span>







轉(zhuǎn)載請(qǐng)注明出處:http://blog.csdn.net/hai_qing_xu_kong/article/details/42361041  情緒控_







生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 美女享受黑人的巨茎 | 亚洲欧美一区二区三区综合 | 亚洲成人免费在线观看 | 国产免费看网站v片不遮挡 国产免费全部免费观看 | 国产一级性片 | www.色图| 亚洲欧美日韩精品久久亚洲区 | freexxxx性特大另类ww | 日本xxxwww在线观看免费 | 国产免费资源高清小视频在线观看 | 欧美一级人与动毛片免费播放 | 欧美成人午夜视频在线观看 | 欧美超清free videos| 国产女人成人精品视频 | 国产乱码精品一区二区三区中 | 最新精品亚洲成a人在线观看 | 国产亚洲精品久久精品6 | 国产亚洲欧美日本一二三本道 | 成人老司机深夜福利久久 | 国产乱码精品一区二区三区卡 | 日本8888xxxx免费视频 | 国产成+人+综合+亚洲不卡 | 在线观看成年人免费视频 | 可以看黄的网址 | 伊人情人综合成人久久网小说 | 久久久久视频精品网 | 成人看片毛片免费播放器 | 美国私人vps一夜爽毛片免费 | 亚洲区欧美 | 精品亚洲在线 | 一级欧美一级日韩毛片99 | 最近中文字幕在线视频 | 久久精品女人毛片国产 | 精品成人一区二区三区免费视频 | 亚洲专区在线播放 | 福利毛片 | 久久久久一区二区三区 | 麻豆天堂 | 欧美一区二区三区在线观看不卡 | 国产精久久一区二区三区 | 国产综合久久一区二区三区 |