Android应用中使用ListView实现数据列表显示(传智播客视频笔记)
2012-06-02 20:09
861 查看
Android应用中使用ListView实现数据列表显示
UsingListViewActivity.java源码:
package com.sinaapp.ssun.listview; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.widget.ListView; import android.widget.SimpleAdapter; public class UsingListViewActivity extends Activity { private List<Person> persons = new ArrayList<Person>(); private ListView listView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); listView = (ListView) this.findViewById(R.id.listView); for(int i=0; i<10; i++){ Person p = new Person("SSUN-"+i,"12340-"+i,i*100); persons.add(p); } show(); } private void show() { List<HashMap<String, Object>> data = new ArrayList<HashMap<String,Object>>(); for(Person p : persons){ HashMap<String, Object> hm = new HashMap<String, Object>(); hm.put("name", p.getName()); hm.put("phone", p.getPhone()); hm.put("amount", p.getAmount()); data.add(hm); } SimpleAdapter adapter = new SimpleAdapter(this,data,R.layout.item, new String[]{"name","phone","amount"}, new int[]{R.id.name,R.id.phone,R.id.amount}); listView.setAdapter(adapter); } } class Person{ private String name; private String phone; private Integer amount; public Person(String name,String phone,Integer amount){ this.name = name; this.phone = phone; this.amount = amount; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public Integer getAmount() { return amount; } public void setAmount(Integer amount) { this.amount = amount; } }
main.xml文件:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <TextView android:textSize="22sp" android:layout_width="100dp" android:layout_height="wrap_content" android:text="@string/name" /> <TextView android:textSize="22sp" android:layout_width="100dp" android:layout_height="wrap_content" android:text="@string/phone" /> <TextView android:textSize="22sp" android:layout_width="100dp" android:layout_height="wrap_content" android:text="@string/amount" /> </LinearLayout> <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout>
item.xml文件:
<?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" > <TextView android:id="@+id/name" android:layout_width="100dp" android:layout_height="wrap_content" android:textSize="22sp" /> <TextView android:id="@+id/phone" android:layout_width="100dp" android:layout_height="wrap_content" android:textSize="22sp" /> <TextView android:id="@+id/amount" android:layout_width="100dp" android:layout_height="wrap_content" android:textSize="22sp" /> </LinearLayout>
string.xml文件:
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">ListView应用</string> <string name="name">姓名</string> <string name="phone">电话</string> <string name="amount">金额</string> </resources>
相关文章推荐
- Android应用中使用ListView实现数据列表显示(传智播客视频笔记)
- Android应用中使用GridView实现数据网格显示(传智播客视频笔记)
- Android采用ListView实现数据列表显示1-使用SimpleCursorAdapter进行数据绑定
- Android采用ListView实现列表数据的显示--Adapter应用
- Android采用ListView实现数据列表显示2-使用SimpleAdapter进行数据绑定
- Android采用ListView实现数据列表显示
- Android采用ListView实现数据列表显示
- [Android新手学习笔记23]-如何使用ListView展示列表数据
- android第十六步采用ListView实现数据列表显示
- Android采用ListView实现数据列表显示
- Android采用ListView实现数据列表显示
- Android开发之listView使用(手机应用列表显示)
- Android实用笔记——使用ListView显示信息列表
- Android学习_19_采用ListView实现数据列表显示
- Android采用ListView实现数据列表显示
- Android应用中使用GridView实现数据网格显示
- Android学习笔记---19_采用ListView实现数据列表显示,以及各种适配器使用,和如何写自己的适配器
- 在Android应用中使用Pull解析XML文件(传智播客视频笔记)
- Android采用ListView实现数据列表显示
- 在Android应用中使用Pull解析XML文件(传智播客视频笔记)