I want to create a list view with limited set of items that isn't really going to change.
Each row is going to have an image on the left and text on the right. (Just like in the Settings app)
Can I populate that in XML (i.e. avoid writing code) ?
It's worth to mentioned that the ListView is a kind of deprecated because the RecyclerView was introduced with the API 21 (Android Lollipop).
To add rows to a ListView you need to add it to your layout and implement an IListAdapter with methods that the ListView calls to populate itself. Android includes built-in ListActivity and ArrayAdapter classes that you can use without defining any custom layout XML or code.
A list view is an adapter view that does not know the details, such as type and contents, of the views it contains. Instead list view requests views on demand from a ListAdapter as needed, such as to display new views as the user scrolls up or down. In order to display items in the list, call setAdapter(android.
I found the answer here: Android - creating listview entirely from xml
"You can use the android:entries
attribute on your ListView
element, pointing to a <string-array>
resource (typically put in res/values/arrays.xml
)."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With