-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