Rohith Nandakumar
Rohith Nandakumar

Reputation: 11427

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

Upvotes: 10

Views: 17611

Answers (3)

Rohith Nandakumar
Rohith Nandakumar

Reputation: 11427

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

Upvotes: 13

Sumant
Sumant

Reputation: 2795

Use ListView tag & specify reqd attr to it. Then take one layout which will hold all the listview in it.Take another layout which will hold image set it's gravity to left. Take diff layout which will hold text set it's gravity to right & put all these in layout 1

Upvotes: 1

Saurabh Pareek
Saurabh Pareek

Reputation: 7134

here is the best example for your question. Custom list view

Upvotes: 2

Related Questions