2012-09-05 25 views
0

我有一个XML文件,我已经成功解析了数据到textView中,现在我想将这些数据绑定到ArrayList或List并将其显示在ListView中。将ArrayList调整为ListView

但我不知道如何将arraylist数据绑定到ListView中。 我已将所有数据成功添加到arraylist中,如下面的代码所述。

List al = new ArrayList(); 
al.add(parser.getAttributeValue(null, "firstnames")); 

请帮助我解决上述问题的代码语法。

问候。

感谢advace

+1

你可以看到答案的解决方案:用图片列表视图(HTTP ://stackoverflow.com/questions/12262989/how-to-4-icons-in-right-side-of-each-row-in-list-view/12263879#12263879)。和:[数据库列表视图](http://stackoverflow.com/questions/12263095/android-linking-a-simple-cursor-to-listview/12264594#12264594) –

+0

行.. @凯尔文特林。 感谢您的帮助。 – Rushabh

回答

1

您需要使用的适配器列表绑定到ListView,像这样:

List<String> list = new ArrayList<String>(); 
// add data to list 

ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list); 
ListView listView = (ListView) findViewById(R.id.listView); 
listView.setAdapter(adapter); 

注意列表的亚型(这是字符串)的亚型匹配ArrayAdapter(也是String)。布局android.R.layout.simple_list_item_1定义了字符串在每一行中的显示方式。你可以在你的SDK中查看这个布局的细节,如果你愿意,你也可以使用你自己的布局。希望有所帮助,祝你好运学习Android!