How to create dynamic data for an item in a list

I created list activity calls as Category List to dynamically display a list of categories from the Internet by parsing an XML file. The XML file contains the values ​​"ID" (identifier of a specific category) and "title" (name of the category). So I did this, I parsed the XML file and put together an identifier and a header in an ArrayList called categories using a SAX parser.

In the list activity, I have a new array of strings and a title for each category is added. What I want to do is assign a category identifier to each category shown in the list view and use the identifier to get the corresponding view for that category. Is there a way to assign an identifier to each of the items in the list.

Regards dj

+3
source share
1 answer

Enter JavaBean and populate it:

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

Create a list and put it in an ArrayList, then populate it Adapter.

http://developer.android.com/reference/android/widget/ArrayAdapter.html, onClicked .. mAdapter.getItem(int). .

SDK.

+1

Source: https://habr.com/ru/post/1777022/


All Articles