Reputation: 9
I am new to android , I have an arraylist
but I want to show its value in a ListView
,but I am unable to do that.I have searched many methods like ArrayAdapter
and BaseAdapter
s etc.but not helpful.Can anyone help me here is my code...
prayerTimes = prayers.getPrayerTimes(cal, latitude,longitude, timezone);
ArrayList prayerNames = prayers.getTimeNames();
for (int i = 0; i < prayerTimes.size(); i++)
{
txtPrayerTimes.append("\n" + prayerNames.get(i) + " - "
+ prayerTimes.get(i));
}
Upvotes: 0
Views: 650
Reputation: 1662
If your list items are strings just use ArrayAdapter
like this
ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, android.R.layout.simepl_list_item_1, arrayList);
If your list items are some objects then extend toString
method for that class and use array adapter for strings again.
EDIT
Or you can extend ArrayAdapter
for the class you want and implement method getView
.
Upvotes: 0
Reputation: 1435
First, Please post your full code. anyway you can use the following code to show tha data in ListView
ListView listView = (ListView) findViewById(R.id.list);
ArrayList<String> list = new ArrayList<String>();
list.add("item1");
list.add("item2");
list.add("item3");
list.add("item4");
list.add("item5");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item1, list);
listView.setAdapter(adapter);
Upvotes: 2
Reputation: 7071
Follow the steps of this tutorial Here you will get description of all points..
Upvotes: 0