Android: how to create a CursorAdapter from data in an XML file

In android, can we create a CursorAdapter from the data in an XML file? Here's the actual problem:

I need to create a ListView whose elements may differ. Each item has three fields: ItemName, ItemValue, ItemUnit. If the adapter is created from an external file (for example: XML file) provided in the application, the number of elements and its field value can be changed without changing the application code. What is the best way to achieve this?

+4
source share
1 answer

You can simply load the data from the xml file into the Maps list, and then use the SimpleAdapter . This is probably the easiest thing. Note that you will need to provide the SimpleAdapter with a mutable map and manually call notifyDataSetChanged whenever the material changes, as described here . If the list is not large (less than 1000 items), you might avoid just creating a new adapter every time your data changes, and then assigning a new adapter to the list.

+1
source

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


All Articles