这是我的NearMe活动。我想在谷歌地图上的标记。然后有人点击标记或叠加我想显示一个警告对话框。这是MapGroupActivity的MapActivity调用
public class NearMeActivity extends MapActivity implements OnClickListener {
private Button imgbtn_map_filter;
private MapView mapView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.nearme_layout);
setMapNOverlay();
setUI();
imgbtn_map_filter.setOnClickListener(this);
final TabGroupActivity parentActivity = (TabGroupActivity) getParent();
parentActivity.closeAllChildsExceptLastOne();
}
private void setUI() {
imgbtn_map_filter = (Button) findViewById(R.id.btn_map_filter);
}
private void setMapNOverlay() {
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.balloon);
MyItemizedOverlay itemezedOverlay = new MyItemizedOverlay(drawable,
this);
GeoPoint point = new GeoPoint(19240000, -99120000);
OverlayItem overlayitem = new OverlayItem(point, "Holaaaa! !!",
"Go away");
itemezedOverlay.addOverlay(overlayitem);
mapOverlays.add(itemezedOverlay);
}
@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_map_filter:
//start activity for result da var onlar incelenecek
Intent intent = new Intent(getParent(), TestActivity.class);
TabGroupActivity parentActivity = (TabGroupActivity) getParent();
parentActivity.startChildActivity ("TestActivity", intent);
break;
default:
break;
}
}
}
这是ItemizedOverlay类。我正在尝试显示一个警告对话框。
public class MyItemizedOverlay extends ItemizedOverlay {
private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
Context mContext;
public MyItemizedOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
mContext = context;
}
//bir Overlay'e dokunduğu zaman olaylar olaylar
@Override
protected boolean onTap(int index) {
OverlayItem item =mOverlays.get(index);
AlertDialog.Builder dialog= new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
try{
dialog.show();
}catch(Exception el){
Log.d("Error: ---->" + e.toString)
}
return super.onTap(index);
}
public void addOverlay(OverlayItem overlay) {
mOverlays.add(overlay);
// ne zaman bir overlay eklesek populate methodunu çalıştırmamız
// gerekmektedir. Yen bir overlay
// nesnesi eklemek için
// populate methodu çalıştığı zaman overlay createItem çalıştıracaktır
populate();
}
// eklenen overlay'in yerini verir.
@Override
protected OverlayItem createItem(int i) {
return mOverlays.get(i);
}
// eklenen yeni overlayın seize'ını almamız gerekmektedir
@Override
public int size() {
return mOverlays.size();
}
}
当我写Toast.makeText(mContext,“Bla bla”,Toast.LENght_LONG).show() - &gt;运行成功 但是警告对话框buider不能使用tap方法。
我正在接受此错误: android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌android.app.LocalActivityManager $ LocalActivityRecord@40532be8无效;你的活动在运行吗?
返回super.onTap(index);
答案 0 :(得分:1)
在NearMeActivity中复制此代码,
@Override
protected Dialog onCreateDialog(int id) {
// TODO Auto-generated method stub
switch (id) {
case 0:
return new AlertDialog.Builder(this).setTitle("Hello").setIcon(
R.drawable.ic_launcher).setPositiveButton("Yes",
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog ,
int which) {
// TODO Auto-generated method stub
}
}).setCancelable(true).setNegativeButton("Cancel",
new OnClickListener() {
@Override
public void onClick(DialogInterface dialog ,
int which) {
// TODO Auto-generated method stub
}
})
.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Dismiss",
Toast.LENGTH_SHORT).show();
}
}).create();
default:
break;
}
return null;
}
从com.google.android.maps.ItemizedOverlay的子类的onTap方法调用此方法以显示对话框:
@Override
protected boolean onTap(int index) {
// TODO Auto-generated method stub
switch (index) {
case 0:
showDialog(0);
break;
}
}