Android UI:ListView - SimpleAdapter實(shí)例詳解
Android UI:ListView -- SimpleAdapter
SimpleAdapter是擴(kuò)展性最好的適配器,可以定義各種你想要的布局,而且使用很方便。
layout :
<?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"> <ListView android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="#7f00" //分割線 android:dividerHeight="2dp" android:id="@+id/listview_sample"/> </LinearLayout>
header layout:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@mipmap/ic_launcher"/> </LinearLayout>
自定義布局 item:
<?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:layout_margin="3px" android:id="@+id/img"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:textSize="16sp" android:id="@+id/title"/> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/info" android:textSize="16sp"/> </LinearLayout> </LinearLayout>
Java 代碼:
public class SampleAdapterActivity extends Activity { private ListView mListview; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.sampleadapter_layout); mListview = (ListView) findViewById(R.id.listview_sample); SimpleAdapter adapter = new SimpleAdapter(this, getData(), //數(shù)據(jù)來(lái)源 R.layout.item_listview, //對(duì)應(yīng)item view new String[]{"img","title","info"}, //data 中對(duì)應(yīng)值 new int[]{R.id.img,R.id.title,R.id.info}); //填充layout位置 mListview.setHeaderDividersEnabled(true); //是否顯示頭view 的分割線 View header = View.inflate(this,R.layout.listview_header,null); View footer = View.inflate(this,R.layout.listview_header,null); mListview.addHeaderView(header); //添加頭部view mListview.addFooterView(footer); //添加底部view mListview.setAdapter(adapter); } @Override protected void onResume() { super.onResume(); } private List<? extends Map<String,?>> getData() { List<Map<String,Object>> items = new ArrayList<Map<String, Object>>(); for (int i = 0; i < 5; i++) { Map<String,Object> item = new HashMap<String,Object>(); item.put("img",R.mipmap.ic_launcher); item.put("title","title -- " + i ); item.put("info","info -- " + i ); items.add(item); } return items; } }
顯示效果
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
- Android自定義Adapter的ListView的思路及代碼
- android開發(fā)中ListView與Adapter使用要點(diǎn)介紹
- Android listview與adapter詳解及實(shí)例代碼
- Android開發(fā)中ListView自定義adapter的封裝
- Android ListView適配器(Adapter)優(yōu)化方法詳解
- Android Adapter里面嵌套ListView實(shí)例詳解
- Android ListView自定義Adapter實(shí)現(xiàn)仿QQ界面
- Android ListView和Adapter數(shù)據(jù)適配器的簡(jiǎn)單介紹
- Android開發(fā)實(shí)現(xiàn)ListView和adapter配合顯示圖片和文字列表功能示例
相關(guān)文章
Android獲得所有存儲(chǔ)設(shè)備位置的最佳方法
今天小編就為大家分享一篇Android獲得所有存儲(chǔ)設(shè)備位置的最佳方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-08-08Android RecyclerView的簡(jiǎn)單使用
這篇文章主要為大家詳細(xì)介紹了Android RecyclerView簡(jiǎn)單使用的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-03-03android不同activity之間共享數(shù)據(jù)解決方法
最近做局域網(wǎng)socket連接問(wèn)題,要在多個(gè)activity之間公用一個(gè)socket連接,就在網(wǎng)上搜了下資料,感覺還是application方法好用,帖出來(lái)需要的朋友可以參考下2012-11-11Android程序開發(fā)通過(guò)HttpURLConnection上傳文件到服務(wù)器
這篇文章主要介紹了Android程序開發(fā)通過(guò)HttpURLConnection上傳文件到服務(wù)器的相關(guān)資料,需要的朋友可以參考下2016-01-01AndroidStudio報(bào)錯(cuò)Emulator:PANIC:Cannot find AVD system path. P
這篇文章主要介紹了AndroidStudio報(bào)錯(cuò)Emulator:PANIC:Cannot find AVD system path. Please define ANDROID_SDK_ROOT完整的解決方案2021-08-08輕松實(shí)現(xiàn)Android3D效果通俗易懂
前幾天有粉絲要求計(jì)蒙寫一個(gè)3d效果的簡(jiǎn)單教程,其實(shí)這個(gè)在Android官方demo中是有的,可能對(duì)于新手而言看不太明白,于是根據(jù)本人自己的理解來(lái)寫一個(gè)教程,并改成粉絲要求的樣子2021-08-08RecyclerView設(shè)置間距和添加分割線的方法
在使用RecyclerView布局,經(jīng)常需要調(diào)整間距和添加分割線以達(dá)到更美觀效果,這篇文章主要介紹了RecyclerView設(shè)置間距和添加分割線的方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-09-09Android Xutils3網(wǎng)絡(luò)請(qǐng)求的封裝詳解及實(shí)例代碼
這篇文章主要介紹了Android Xutils3網(wǎng)絡(luò)請(qǐng)求的封裝詳解及實(shí)例代碼的相關(guān)資料,需要的朋友可以參考下2016-12-12Android最簡(jiǎn)單的限制輸入方法(只包含數(shù)字、字母和符號(hào))
這篇文章主要給大家介紹了關(guān)于Android最簡(jiǎn)單的限制輸入的實(shí)現(xiàn)方法,限制輸入框只能輸入數(shù)字、字母和符號(hào),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看 吧2018-11-11Android動(dòng)畫之補(bǔ)間動(dòng)畫(Tween Animation)基礎(chǔ)學(xué)習(xí)
補(bǔ)間動(dòng)畫是指定開始和結(jié)束的圖像狀態(tài),自動(dòng)生成需要顯示的過(guò)度圖像的動(dòng)畫。補(bǔ)間動(dòng)畫又分為四種:移動(dòng),縮放,旋轉(zhuǎn),通明度等。下面就來(lái)給大家一篇關(guān)于Android中補(bǔ)間動(dòng)畫的基礎(chǔ)知識(shí),有需要的可以參考學(xué)習(xí)。2016-09-09