I read data from database:
private MyDatabase db;
private Cursor cities;
private ListAdapter cityListAdapter;
private ListView citiesListView;
db = new MyDatabase(getContext());
cities = db.getCities();
And set an adapter for it:
cityListAdapter = new SimpleCursorAdapter(getContext(),
android.R.layout.simple_list_item_1,
cities,
new String[] {"city"},
new int[] {android.R.id.text1},0);
citiesListView.setAdapter(cityListAdapter);
I can see the ListView populated correctly. But when I try to get an item's string, I get a strange string instead: android.database.sqlite.SQLiteCursor@4251fac0
Here's my code for this:
citiesListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
String str = cityListAdapter.getItem(position).toString();
chosenCityTextView.setText(str);
}
});
Why am I not getting the string that appears in the ListView?
Aucun commentaire:
Enregistrer un commentaire