我正在开发一个 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()方法上,那么为什么自定义警报对话框在单击时没有关闭。在此先感谢大家