![](/img/trans.png)
[英]How to use onCreateOptionsMenu() in Activity Which Extended ListActivity
[英]How to use listActivity and mapActivity together
我同時使用MapActivity
和ListActivity
在地圖上顯示商店位置。 商店來自清單。 我使用setListAdapter(adapter)
但不支持。 我也使用ListView
,它給出了setAdapter(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);
}
這不是完整的代碼...而且我不確定您的應用程序的流程。 您是否在使用ListActivity,即用戶選擇一個項目然后打開MapActivity? 您不能將ListActivity和MapActivity合二為一。 您必須將ListView或MapView添加到適當的活動中。 如果您使用MapActivity,則仍然需要調用setContentView()
並設置布局(其中包含MapView和ListView)。
根據您需要執行的操作,您還可以使用ListFragment並在其中定義列表所需的所有邏輯和功能,然后將其添加到MapActivity中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.