android studio listview实现列表数据显示
样式不好看!想要好看的样式可以私我,我加!
item.xml
main.xml
mainactivity .java
public class mainactivity extends activity { listlist; list 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 > data = new arraylist >(); for(int i = 0; i < list .size(); i ){ hashmap item = new hashmap (); 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); } }