0

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 BaseAdapters 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));              
}
2
  • what is the error you are getting? and post your code what you have tried till now Commented Apr 9, 2014 at 7:42
  • can u add logcat and post your code Commented Apr 9, 2014 at 7:50

4 Answers 4

2

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);
Sign up to request clarification or add additional context in comments.

Comments

0

Follow the steps of this tutorial Here you will get description of all points..

Comments

0

A simple tutorial for list view with array list you should follow.

Comments

0

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.

1 Comment

See the updated answer, and also try to Google a bit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.