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);
setListAdapter(fileList);
the answer to this question is:
Obtain the reference of your ListView
using findViewById(int)
. Then call the method ListView.setAdapter(ListAdapter)
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, R.id.text1, items);
setListAdapter(adapter);
}
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.
An activity that displays a list of items by binding to a data source such as an array or Cursor, and exposes event handlers when the user selects an item. ListActivity hosts a ListView object that can be bound to different data sources, typically either an array or a Cursor holding query results.
Obtain the reference of your ListView using findViewById(int) . Then call the method ListView. setAdapter(ListAdapter) on that reference with your adapter as the parameter.
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, R.id.text1, items);
ListView lv = (ListView)findViewById(R.id.your_listview_id);
lv.setAdapter(adapter);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With