开发者

how to generate dynamic data for an item in listview

I have created a list activity calles as Category List to show a list of category dynamically from web by parsing an XML file. The XML file contains values "ID"(id of the particular category) and "title"(category name). So what I've done is, I've parsed the XML file and collected the ID and title to an ArrayList called categries using SAX parser.

In the list activity, I have a created a new string array and added the title of each category to it. T开发者_开发知识库he thing I want to do is to assign the category id to each category shown in the list view and to use the id to get the appropriate view for that category. Is there any way to assign an id to the each of the list items.

regards dj


Introduce a JavaBean, and fill it:

class YourBean {
  private int id;
  private String title;
  // add get / set methods
}

Create the list and put it in a ArrayList ,then fill a Adapter with it.

Then, you can use an http://developer.android.com/reference/android/widget/ArrayAdapter.html and in your onClicked etc method use mAdapter.getItem(int). That's in very short words.

Take a look in the SDK examples.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜