0

我使用MapActivityListActivity一起在地图上显示商店位置。商店来自列表。我用过setListAdapter(adapter),但不支持。我也使用ListViewwhich 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);
    }
4

1 回答 1

0

This isn't the complete code... And I'm a little unsure of the flow of your app. Are you using a ListActivity where a user selects an item and then you open a MapActivity? You can't have a ListActivity and a MapActivity in one. You'll have to add either ListView or MapView into the appropriate activity. If your using a MapActivity you'll still need to call setContentView() and set your layout (which contains your MapView and ListView).

Depending on what you need to do, you could also use a ListFragment and define all of the logic and functionality required for your list in there and just add it to your MapActivity.

于 2012-08-27T12:44:10.990 回答