Luch Filip Luch Filip - 8 months ago 49
Android Question

how to correctly call setListAdapter

I've searched how to solve this problem a lot, but i did not get any result. the only help that i need is, please take a look at this question asked on stackoverflow and on answer;

here is the question from this link:

"my activity does not extend ListActivity so this line throws an error. setListAdapter(fileList); it is supposed to populate a listview..."

ArrayAdapter<String> fileList =
new ArrayAdapter<String>(this, R.layout.row, item);

the answer to this question is:

Obtain the reference of your
. Then call the method
on that reference with your adapter as the parameter.

now here is my code:

ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, R.layout.reminder_row,, items);



considering the Q/A, could someone please explain how exactly do i write it in the correct way. Any help would be very much appreciated.


As explained in the linked question and in this question's comments, it goes like this:

ArrayAdapter<String> adapter =new ArrayAdapter<String>(this, R.layout.reminder_row,, items);
ListView lv = (ListView)findViewById(;

ListActivity is a specialized Activity that hosts a ListView and has some convenience methods for accessing and manipulating it. However, nothing prevents you from having a ListView in a non-ListActivity Activity, you just lose the convenience methods and will have to write some more code yourself, like above.