直接看例子吧!
// 创建PopupWindow对象
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.popmenu_location, null); // 引入窗口配置文件
final PopupWindow pop = new PopupWindow(view, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, false);
//plain是popupWindow其中的一个组件
plain=(ImageButton)view.findViewById(R.id.plain);
plain.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Log.i(TAG,"plain clicked");
if(satelliteisshow==true){
mMapView.setSatellite(false);//关闭卫星图
Log.i(TAG,"satellite is closed!");
satelliteisshow=false;
}else if(threedisshow==true){
mMapView.getController().setOverlooking(0);//关闭3D图
Log.i(TAG,"three_d is closed!");
threedisshow=false;
}
}
});
这里只要注意一个问题,plain定义的时候是用view组件中的一个item,这样就可以获取它的单击事件了!