Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Create ListView in XML?

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) ?

like image 705
Rohith Nandakumar Avatar asked Mar 16 '11 09:03

Rohith Nandakumar


People also ask

Is ListView deprecated android?

It's worth to mentioned that the ListView is a kind of deprecated because the RecyclerView was introduced with the API 21 (Android Lollipop).

How do you populate a ListView?

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.

What is a list view in android studio?

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.


1 Answers

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)."

like image 83
Rohith Nandakumar Avatar answered Sep 20 '22 17:09

Rohith Nandakumar