-1
我想填充的ListView,如http://www.tutorialspoint.com/android/android_list_view.htm 它工作正常(见下面的代码)移植ListView多维的ArrayList
//字符串数组... 的String [] mobileArray = {“机器人“,”iPhone“,”WindowsMobile“,”Blackberry“,”WebOS“,”Ubuntu“,”Windows7“,”Max OS X“};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_listview, mobileArray);
ListView listView = (ListView) findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
}
现在,而不是这个mobileArray(一个维数组),我想用一个ArrayList
我已经填充的ArrayList名为学生
但是当我填充它为:
ArrayAdapter adapter = new ArrayAdapter<Student>(this, R.layout.activity_listview,Students);
ListView listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(adapter);
和运行,我得到一个奇怪的输出
[email protected]
[email protected]
[email protected]
其实学生有3行......但是,没有价值观,如e3c94gh
请帮我用最少的代码改变这一点 - 我的意思是 -
我的目标就是与学生们进行替换mobileArray(用最少的代码改变)
ArrayList population code is here:
List<Student> Students = new ArrayList();
Student student1 = new Student();
student1.setStudentName("student 1");
student1.setStudentNo("N0001");
student1.setEmail("[email protected]");
student1.setYear(1991);
Students.add(student1);
Student student2 = new Student();
student2.setStudentName("Student 2");
student2.setStudentNo("N0002");
student2.setEmail("[email protected]");
student2.setYear(1992);
Students.add(student2);
Student student3 = new Student();
student3.setStudentName("Student 3");
student3.setStudentNo("N0003");
student3.setEmail("[email protected]");
student3.setYear(1993);
Students.add(student3);
应用更改ArrayAdapter。根本没有改变。我将更新ArrayList人口步骤 –
尝试更改“R.layout.activity_listview”=== >>>“android.R.layout.simple_list_item_1” – alway5dotcom
如果您想在一行ListView中显示多个信息,那么您必须定制它。这里是你需要开始的地方:http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/ – alway5dotcom