android关于触摸任何位置都可以关闭的对话框的问题
调用代码:publicvoidShowAlertDialog(){MyAlertDialog.Builderbuilder=newMyAlertDialog.Builde...
调用代码:
public void ShowAlertDialog(){
MyAlertDialog.Builder builder = new MyAlertDialog.Builder(MapActivity.this);
builder.setTitle("当前所处位置?");
builder.setItems(new String[]{"黄河路339号","北京饭店","图书馆","快捷酒店"}, null);
builder.setView(getLayoutInflater().inflate(R.layout.localalertdialog, null));
MyAlertDialog localdialog=(MyAlertDialog)builder.create();
localdialog.show();
EditText addlocationedit=(EditText)localdialog.findViewById(R.id.addLocation);
}
public class MyAlertDialog extends AlertDialog{
protected MyAlertDialog(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
this.dismiss();
return super.onTouchEvent(event);
}
}
出现的异常:
E/AndroidRuntime(32107): FATAL EXCEPTION: main
E/AndroidRuntime(32107): java.lang.ClassCastException: android.app.AlertDialog
E/AndroidRuntime(32107): at com.sqc.abc.BaiduMapActivity.ShowAlertDialog(BaiduMapActivity.java:231)
E/AndroidRuntime at com.sqc.abc.BaiduMapActivity$LawLocationOverlay.onTap(BaiduMapActivity.java:221)
E/AndroidRuntime(32107): at com.baidu.mapapi.a.a(Unknown Source)
E/AndroidRuntime(32107): at com.baidu.mapapi.MapView.onTouchEvent(Unknown Source) 展开
public void ShowAlertDialog(){
MyAlertDialog.Builder builder = new MyAlertDialog.Builder(MapActivity.this);
builder.setTitle("当前所处位置?");
builder.setItems(new String[]{"黄河路339号","北京饭店","图书馆","快捷酒店"}, null);
builder.setView(getLayoutInflater().inflate(R.layout.localalertdialog, null));
MyAlertDialog localdialog=(MyAlertDialog)builder.create();
localdialog.show();
EditText addlocationedit=(EditText)localdialog.findViewById(R.id.addLocation);
}
public class MyAlertDialog extends AlertDialog{
protected MyAlertDialog(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
this.dismiss();
return super.onTouchEvent(event);
}
}
出现的异常:
E/AndroidRuntime(32107): FATAL EXCEPTION: main
E/AndroidRuntime(32107): java.lang.ClassCastException: android.app.AlertDialog
E/AndroidRuntime(32107): at com.sqc.abc.BaiduMapActivity.ShowAlertDialog(BaiduMapActivity.java:231)
E/AndroidRuntime at com.sqc.abc.BaiduMapActivity$LawLocationOverlay.onTap(BaiduMapActivity.java:221)
E/AndroidRuntime(32107): at com.baidu.mapapi.a.a(Unknown Source)
E/AndroidRuntime(32107): at com.baidu.mapapi.MapView.onTouchEvent(Unknown Source) 展开
展开全部
private void showAlertDialog() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("当前所处位置?");
recoverBuilder.setItems(new String[]{"黄河路339号","北京饭店","图书馆","快捷酒店"},
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {}});
AlertDialog alert = builder.create();
alert.setCanceledOnTouchOutside(true);
alert.show();
}
去试试
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("当前所处位置?");
recoverBuilder.setItems(new String[]{"黄河路339号","北京饭店","图书馆","快捷酒店"},
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {}});
AlertDialog alert = builder.create();
alert.setCanceledOnTouchOutside(true);
alert.show();
}
去试试
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询