国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

Android studio listview實現列表數據顯示 數據循環顯示效果

瀏覽:119日期:2022-09-24 17:07:35

Android studio listview實現列表數據顯示

Android studio listview實現列表數據顯示 數據循環顯示效果

樣式不好看!想要好看的樣式可以私我,我加!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: /> <!-- 性別--> <TextView android:layout_width='150dp' android:layout_height='wrap_content' android: /></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' > <!-- 標題 --> <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: /></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);//獲取到集合數據 //名字列表,之后可以動態加入數據即可,這里只是數據例子 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); } //創建SimpleAdapter適配器將數據綁定到item顯示控件上 SimpleAdapter adapter = new SimpleAdapter(MainActivity.this, data, R.layout.item, new String[]{'name', 'sex'}, new int[]{R.id.name, R.id.sex}); //實現列表的顯示 listView.setAdapter(adapter); }}

總結

到此這篇關于Android studio listview實現列表數據顯示 數據循環顯示效果的文章就介紹到這了,更多相關Android studio listview數據顯示 內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Android
相關文章:
主站蜘蛛池模板: 岑溪市| 奉贤区| 昂仁县| 浦城县| 南充市| 大关县| 武山县| 广饶县| 金乡县| 邢台市| 浮山县| 中牟县| 宁城县| 长寿区| 金坛市| 三台县| 铜陵市| 汶川县| 开化县| 武安市| 锦州市| 神农架林区| 保康县| 石屏县| 彩票| 盘山县| 巴马| 天水市| 昭平县| 拉萨市| 同德县| 台山市| 济宁市| 澄江县| 临安市| 永城市| 沛县| 宣化县| 三明市| 颍上县| 延庆县|