我使用MapActivity
和ListActivity
一起在地图上显示商店位置。商店来自列表。我用过setListAdapter(adapter)
,但不支持。我也使用ListView
which givesetAdapter(adpt)
但我得到Null pointer exception
.
这是我的代码:
public void search(View view) {
// || is the concatenation operation in SQLite
listView=(ListView) findViewById(R.id.list);
try{
cursor = db.rawQuery("SELECT _id, store FROM storeInfo WHERE address LIKE ?",
new String[]{"%" + searchText.getText().toString() + "%"});
adapter = new SimpleCursorAdapter(
this,
R.layout.store_list_item,
cursor,
new String[] {"store"},
new int[] {R.id.store});
listView.setAdapter(adapter);
}catch(Exception e){
System.out.println("Exception::"+e);
}
public void onItemClick(AdapterView parent, View view, int position, long id) {
Intent intent = new Intent(this, StoreDetails.class);
Cursor cursor = (Cursor) adapter.getItem(position);
//Cursor cursor = (Cursor) listView.getAdapter().getItem(position);
intent.putExtra("STORE_ID", cursor.getInt(cursor.getColumnIndex("_id")));
startActivity(intent);
}