如何一起使用listActivity和mapActivity

时间:2012-08-27 12:34:06

标签: java android

我一起使用MapActivityListActivity来显示地图上的商店位置。商店来自清单。我使用setListAdapter(adapter)但它不会支持。我也使用了ListViewsetAdapter(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);
    }

1 个答案:

答案 0 :(得分:0)

这不是完整的代码......我对你的应用流程有点不确定。您是否正在使用ListActivity,用户选择一个项目,然后打开MapActivity?您不能将ListActivity和MapActivity合二为一。您必须将ListView或MapView添加到相应的活动中。如果你使用MapActivity,你仍然需要调用setContentView()并设置你的布局(包含你的MapView和ListView)。

根据您的需要,您还可以使用ListFragment并定义列表中所需的所有逻辑和功能,并将其添加到MapActivity中。