为什么我的dismiss()方法无法关闭“自定义警报”对话框

时间:2013-10-27 07:57:13

标签: android alertdialog dismiss

我正在开发一个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和builde,如下所示: -

 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()用于某些Cursor使用数据库

    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()方法然后为什么自定义警报对话框没有在点击时关闭。在此先感谢所有

1 个答案:

答案 0 :(得分:0)

您应该在final私有变量中添加orderDialog