开发者

How to display List<> using ListView?

When I use ListView to display a array of my object, I can use the following code:

MyObject[] myObject;
...  
ArrayAdapter<MyObject> itemList = new ArrayAdapter<MyObject>(this, R.layout.list, myObject);   
setListAdapter(itemList);

In case that the input is a list:

List<MyObject> myobj开发者_如何学Goect;

How can I assign it to ListAdapter? Please advise, Thx!


There is another constructor for ArrayAdapter that takes in a list:

ArrayAdapter(Context context, int textViewResourceId, List<T> objects)

See ArrayAdapter java doc for a complete list!


Even the question seems already to be answered, i'd like to mention using custom listviews with a custom adapter:

There is a great tutorial how to use a listview

http://developerlife.com/tutorials/?p=327

a second tutorial (in 6 parts) you can find here:

http://www.androidguys.com/2008/07/14/fancy-listviews-part-one/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜