Android studio listview實(shí)現(xiàn)列表數(shù)據(jù)顯示 數(shù)據(jù)循環(huán)顯示效果
Android studio listview實(shí)現(xiàn)列表數(shù)據(jù)顯示
樣式不好看!想要好看的樣式可以私我,我加!
item.xml
<?xml version="1.0" encoding="utf-8"?> <!--item --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <!--姓名 --> <TextView android:layout_width="130dp" android:layout_height="wrap_content" android:id="@+id/name" /> <!-- 性別--> <TextView android:layout_width="150dp" android:layout_height="wrap_content" android:id="@+id/sex" /> </LinearLayout>
main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <!-- 標(biāo)題 --> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:layout_width="130dp" android:layout_height="wrap_content" android:text="姓名" /> <TextView android:layout_width="150dp" android:layout_height="wrap_content" android:text="姓名" /> </LinearLayout> <!-- ListView控件 --> <ListView android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/listView" /> </LinearLayout>
MainActivity .java
public class MainActivity extends Activity { List<String> list; List<String> list1; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ListView listView = (ListView) this.findViewById(R.id.listView); //獲取到集合數(shù)據(jù) //名字列表,之后可以動態(tài)加入數(shù)據(jù)即可,這里只是數(shù)據(jù)例子 list = new ArrayList<>(); list.add("小明"); list.add("李華"); list.add("張三"); list1 = new ArrayList<>(); list1.add("男"); list1.add("男"); list1.add("女"); List<HashMap<String, Object>> data = new ArrayList<HashMap<String,Object>>(); for(int i = 0; i < list .size(); i++){ HashMap<String, Object> item = new HashMap<String, Object>(); item.put("name", list.get(i)); item.put("sex", list1.get(i)); data.add(item); } //創(chuàng)建SimpleAdapter適配器將數(shù)據(jù)綁定到item顯示控件上 SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, data, R.layout.item, new String[]{"name", "sex"}, new int[]{R.id.name, R.id.sex}); //實(shí)現(xiàn)列表的顯示 listView.setAdapter(adapter); } }
總結(jié)
到此這篇關(guān)于Android studio listview實(shí)現(xiàn)列表數(shù)據(jù)顯示 數(shù)據(jù)循環(huán)顯示效果的文章就介紹到這了,更多相關(guān)Android studio listview數(shù)據(jù)顯示 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- Android使用RecyclerView實(shí)現(xiàn)列表數(shù)據(jù)選擇操作
- kotlin android extensions 插件實(shí)現(xiàn)示例詳解
- 一文讀懂Android?Kotlin的數(shù)據(jù)流
- Android使用ViewBinding的詳細(xì)步驟(Kotlin簡易版)
- Android入門之使用RecyclerView完美實(shí)現(xiàn)瀑布流界面詳解
- Android列表組件ListView使用詳解之動態(tài)加載或修改列表數(shù)據(jù)
- Android kotlin RecyclerView遍歷json實(shí)現(xiàn)列表數(shù)據(jù)的案例
相關(guān)文章
Android ListView列表優(yōu)化的方法詳解
列表 ListView 是應(yīng)用中最為常見的組件,而列表往往也會承載很多元素,這時(shí)就需要對其進(jìn)行優(yōu)化。本文介紹了 Flutter ListView 的4個(gè)優(yōu)化要點(diǎn),非常實(shí)用,需要的可以參考一下2022-05-05Android仿新浪微博oauth2.0授權(quán)界面實(shí)現(xiàn)代碼(2)
這篇文章主要為大家詳細(xì)介紹了Android仿新浪微博oauth2.0授權(quán)界面實(shí)現(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-11-11android webview獲取html代碼和根據(jù)id獲取value實(shí)例
這篇文章主要介紹了android webview獲取html代碼和根據(jù)id獲取value實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03Android開發(fā)中MotionEvent坐標(biāo)獲取方法分析
這篇文章主要介紹了Android開發(fā)中MotionEvent坐標(biāo)獲取方法,結(jié)合實(shí)例形式分析了MotionEvent獲取坐標(biāo)的相關(guān)函數(shù)使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-02-02Android 調(diào)用系統(tǒng)相機(jī)拍攝獲取照片的兩種方法實(shí)現(xiàn)實(shí)例
這篇文章主要介紹了Android 調(diào)用系統(tǒng)相機(jī)拍攝獲取照片的兩種方法實(shí)現(xiàn)實(shí)例的相關(guān)資料,一種是通過Bundle來獲取壓縮過的照片,一種是通過SD卡獲取的原圖,需要的朋友可以參考下2016-11-11Android實(shí)現(xiàn)實(shí)時(shí)滑動ViewPager的2種方式
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)實(shí)時(shí)滑動ViewPager的2種方式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10