【发布时间】:2013-11-06 02:35:19
【问题描述】:
我正在开发一个 android 应用程序,我在其中创建了自定义警报对话框。我声明全局警报对话框和 AlertDialog.builder 如下。现在我在按钮点击中调用了三个方法f1()、f2()、f3()。
btn_my_order.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
f1();
f2();
f3();
return false;
}
});
我声明 orderDialog 并全局构建如下:-
private AlertDialog orderDialog = null;
AlertDialog.Builder builder;
我的 f1() 块如下:-
F1{
builder = new AlertDialog.Builder(MainScreen.this);
mContext = getApplicationContext();
/**
* by the help of inflater my ordre is showing in list view
*/
inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
orderDialogLayout = inflater.inflate(R.layout.my_order_list,(ViewGroup)findViewById(R.id.order_list_root));
orderList = (ListView) orderDialogLayout.findViewById(R.id.order_list);
ibOrderDelete = (ImageButton)orderDialogLayout.findViewById(R.id.deleteOrder);
tvPrice = (TextView) orderDialogLayout.findViewById(R.id.order_list_total);
tvTaxes = (TextView) orderDialogLayout.findViewById(R.id.order_list_taxes);
tvTotal = (TextView) orderDialogLayout.findViewById(R.id.order_list_grand_total);
Button bclose = (Button) orderDialogLayout.findViewById(R.id.close);
Button bPlaceOrder = (Button) orderDialogLayout.findViewById(R.id.my_order_placeorder);
bclose.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
orderDialog.dismiss();
System.out.println(" click on close button");
}
});
/**
* click of place order to kitchen
*/
bPlaceOrder.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
System.out.println("Place order click");
palceMyOrdertoServer();
new SendOrderFromTable().execute();
System.out.println("place order to server is called");
String msg = "Your Order is Successfully placed to Kitcken";
Message msgObject = new Message();
msgObject.what = 1;
msgObject.obj = msg;
addMenuItemHandler.sendMessage(msgObject);
orderDialog.dismiss();
}
});}
我的 f2() 用于一些与数据库一起使用的光标
F2{
// many stuff to be here populate data from cursor and bind it with adapter
// no any issue in this mehod
}
现在我终于调用 f3()
F3{
builder.setView(orderDialogLayout);
orderDialog = builder.create();
orderDialog.show();
}
现在我要解释我所有的问题 f1() 方法用于初始化 f2() 用于填充数据,而 f3() 用于显示自定义警报对话框。为什么我的
orderDialog.dismiss();
不适合我。即使我能够看到带有消息的 logcat
"Click on close button"
这意味着执行正在dismiss() 方法上,那么为什么自定义警报对话框在单击时没有关闭。在此先感谢大家
【问题讨论】:
-
这是因为您在 f3 中初始化 orderDialog 时在 f1 中将其关闭
-
@Raghunandan ..这意味着如果我在 f3() 中调用了dismiss,那么它可以工作吗?..感谢您的快速回复..
-
试试看告诉我
-
@Raghunandan.. 我试过你的建议,但仍然遇到同样的问题.. 请帮我解决这个问题
-
确定 orderDialog 已显示/?
标签: android android-alertdialog dismiss