开发者

How To Set the Text of an item in ListView

I have a list of ListItems's in my listview. Th开发者_如何学编程e ListItem has a name instance variable. I am trying to get the text of each of the items just to be the name.

How can I do this?

 public class List extends ListActivity  {
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
          setListAdapter(new ArrayAdapter<ListItem>(this, R.layout.list_item, Previousclass.LinkedList-from-previous-class));

Right now it is just displaying the memory location of each item i.e. ListItem@47234c10


You have to extend ArrayAdapter to implement getView(). The ArrayAdapter implementation is returning the toString() value of your ListItem object.

Or alternatively stringify your data before adding it to the adapter.


What is Previousclass.LinkedList-from-previous-class ? Is it a list of your items?

If yes, Your list of items should be a list of names of items. Your resulting screen should have listview in it and the adapter you created should be used this way

result.setListAdapter(Youradapter)

I am just giving you sample based on what code you have posted. If you need details, please elaborate your code.

result.setListAdapter(new ArrayAdapter<ListItem>(this, R.layout.list_item, Previousclass.LinkedList-from-previous-class))
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜