// get the instance of ListView
ListView listView = (ListView)findViewById(R. id.listView);
// define a String array
final String[] catNames = new String[] {
"Ginger", "Barsik", "Murzik"
};
// use the data adapter
ArrayAdapter<string> adapter = new ArrayAdapter<string>(this,
android.R.layout.simple_list_item_1, catNames);
listView.setAdapter(adapter);</string></string>
ListView listView = (ListView)findViewById(R. id.listView);
listView.add("ginger");
listView.add("snow leopard");
listView.add("Murzik");
Why on Android you can't use lists without adapters?
the ListView
is responsible to use the provided widgets in the list view and Adapter
is responsible for creating the supplied widgets. ListView
new widgets you need to ArrayAdapter
, as you have two dozen items you get from the network, and you can store them in memory, and (exaggerating) tomorrow elements is two thousand and remember to keep not comme Il faut, accordingly, you decide to tie the caching of items in the database, and now you need a CursorAdapter
.Collection
, and the responsibility "to sort the items" - on classes that implement the interface Iterator
, although it would be possible to dump everything in one pile.listView.addView(view);
Find more questions by tags Android