2 u012257679 u012257679 于 2016.04.16 16:39 提问

关于android中listview点击item没有反应

public class MapActivity extends BasePagerActivity {
private MapView mMapView = null;
private BaiduMap mBaiduMap;
private ListView map_menu_lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
initData();
}

@Override
public void initData() {
    base_tv_title.setText("街景秀");
    SDKInitializer.initialize(getApplicationContext());
    View view = View.inflate(MapActivity.this, R.layout.map, null);
    map_menu_lv = (ListView) view.findViewById(R.id.map_menu_lv);
    map_menu_lv.setAdapter(new MapMenuListViewAdapter(MapActivity.this));
    weibo_menu.setVisibility(View.VISIBLE);
    weibo_menu.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            //Toast.makeText(MapActivity.this, "wo", 1).show();
            map_menu_lv.setVisibility(View.VISIBLE);
        }
    });

    mMapView = (MapView) view.findViewById(R.id.bmapView);
    mBaiduMap = mMapView.getMap();
    MapStatusUpdate msu = MapStatusUpdateFactory.zoomTo(15.0f);
    mBaiduMap.setMapStatus(msu);
    **map_menu_lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            switch (arg2) {
            case 0:
                mBaiduMap.setMapType(BaiduMap.MAP_TYPE_NORMAL);
                break;
            case 1:
                mBaiduMap.setMapType(BaiduMap.MAP_TYPE_SATELLITE);
                break;
            case 2:
                if(mBaiduMap.isTrafficEnabled()){
                    mBaiduMap.setTrafficEnabled(false);
                }else{
                    mBaiduMap.setTrafficEnabled(true);
                }
                break;

            default:
                break;**
            }
        }
    });
    base_fr.addView(view);
}

@Override
protected void onDestroy() {
    super.onDestroy();
    // 在activity执行onDestroy时执行mMapView.onDestroy(),实现地图生命周期管理
    mMapView.onDestroy();
}

@Override
protected void onResume() {
    super.onResume();
    // 在activity执行onResume时执行mMapView. onResume (),实现地图生命周期管理
    mMapView.onResume();
}

@Override
protected void onPause() {
    super.onPause();
    // 在activity执行onPause时执行mMapView. onPause (),实现地图生命周期管理
    mMapView.onPause();
}

}

请问标识出的部分为什么不能起到切换百度地图状态的功能?

3个回答

CSDNXIAOD
CSDNXIAOD   2016.04.16 16:42

点击Android ListView 某一项item无反应解决办法
android中listview点击item不变色的问题
android listview item 点击无效解决
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

crazy1235
crazy1235   Ds   Rxr 2016.04.16 20:26
sinat_21102069
sinat_21102069   2016.05.15 17:49

我看你的类都没有实现点击事件的接口,你是怎么写的setOnClickListener

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!