Android学习第三天--listview方式五
2013-03-10 00:22
323 查看
xml
java文件
person类
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <ListView android:id="@+id/listview1" android:layout_width="match_parent" android:layout_height="wrap_content"/> </RelativeLayout>
java文件
import java.util.ArrayList; import java.util.List; import cn.core.entity.Person; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView listView=(ListView)findViewById(R.id.listview1); List <Person> list= new ArrayList<Person>(); Person person1=new Person(1, "是东方闪电", "男"); Person person2=new Person(3, "燕方法", "男"); list.add(person1); list.add(person2); ArrayAdapter<Person> arrayAdapter =new ArrayAdapter<Person>(this, android.R.layout.simple_list_item_1, list); listView.setAdapter(arrayAdapter); } }
person类
public class Person { private Integer userId; private String userName; private String userSex; public Person() { super(); } public Person(Integer userId, String userName, String userSex) { super(); this.userId = userId; this.userName = userName; this.userSex = userSex; } public Integer getUserId() { return userId; } public void setUserId(Integer userId) { this.userId = userId; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public String getUserSex() { return userSex; } public void setUserSex(String userSex) { this.userSex = userSex; } @Override public String toString() { return "Person [userId=" + userId + ", userName=" + userName + ", userSex=" + userSex + "]"; } }
相关文章推荐
- Android学习第三天--listview方式一
- Android学习第三天--listview方式四
- Android学习第三天--listview方式二
- Android学习第三天--listview方式六
- Android学习第三天--listview方式三
- Android学习第三天--listview方式七
- Android学习 —— 多种适配器方式实现ListView
- Android学习 —— 多种适配器方式实现ListView
- android学习记录3(数据存储的方式:sqlite、sp、存文件。listview简单使用)
- 【android基础学习之二】——基础控件ListView
- android基础学习10——Listview的使用及其数据适配
- Android学习之ListView
- android中expandablelistview的学习
- Android ListView学习笔记
- Android学习之视频音乐列表ListView
- android 使用代码方式创建自定义progressBar——自定义控件学习(六)
- Android ListView控件的学习
- Android UI学习 - ListView (android.R.layout.simple_list_item_1是个什么东西)
- android 项目学习随笔十七(ListView、GridView显示组图)
- Android控件学习之ListView