Possible to displaying Arraylist of object's value in setListAdapter or SimpleAdapter for listview?
HI,
I would like 开发者_如何学Goto know if it is possible to display Arraylist of object's value in setListadapter or SimpleAdapter for listview?
String ArrayList works fine, I am just trying my luck with Object ArrayList
ArrayList<userinfo> list = new ArrayList<userinfo>();
setListAdapter(new ArrayAdapter<userinfo>(this, R.layout.messages, list)); // list.???
userinfo class consist of all the getters and setters.
String ArrayList(Working Version) @ http://developer.android.com/resources/tutorials/views/hello-listview.html
Simplest solution is to implement userinfo.toString() method - then ArrayAdapter will automatically use this method to get string values from your objects. If you don't want to do that this way, you could overwrite ArrayAdapter.getView() method and create View objects manually.
Yes, it is possible now just set your setLIstAdapter as an Object type.
setListAdapter(new ArrayAdapter(getActivity(), android.R.layout.simple_list_item_1, userinfo));
精彩评论