代码之家  ›  专栏  ›  技术社区  ›  DJhon

Dismiss()不适用于自定义警报对话框

  •  1
  • DJhon  · 技术社区  · 11 年前

    我正在开发一个完全基于servlet请求和响应的android应用程序。我已经在自定义警报对话框中填充了一些数据。我使用了两件事——第一件事是交叉按钮,它将从警报对话框的列表中删除项目并更新警报对话框的视图,第二件事是关闭按钮,它可能会关闭这个警报对话框。我正在显示我的警报对话框的完整编码。我通过所有这些方法点击按钮调用警报对话框。

     intiliazeOrderListDialog();
     showOrderListDialog();
    

    我的心情如下

    public AlertDialog detailsDialog, orderDialog;
    AlertDialog.Builder builder;
    

    现在我要发布我的intiliazeOrderListDialog()块。

        public void intiliazeOrderListDialog() {  
    
        builder = new AlertDialog.Builder(MainScreen.this);
        mContext = getApplicationContext();
    
        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 closowse");
    
            }      
        });
    
        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();
    
            }
        }); 
    }
    

    最后我要发布showOrderListDialog();块

      public void showOrderListDialog() {  
        builder.setView(orderDialogLayout);
        orderDialog = builder.create();
        orderDialog.show();
    }
    

    我知道我发布了太多代码,但这对那些想帮助我的人来说很方便。我有一个很简单的问题

                orderDialog.dismiss();
    

    对我不起作用。?提前感谢所有人。

    1 回复  |  直到 11 年前
        1
  •  1
  •   DJhon    11 年前

    最后我解决了我自己的问题。“自助是最好的帮助;”。

    这是调用setOnClickListener中的方法的问题。

    我只是这么称呼它,

    android:clickable="true"
    android:onClick="clickHandler"
    
        if (v.getId() == R.id.myOrder) {
            System.out.println("Click my Order");
            System.out.println("OrderListAdapter.totalCount  ="
                    + OrderListAdapter.totalCount);
            // select COUNT(*) from CDs;
    
            int jcount = 0;
            jcount = countjournals();
            System.out.println("jcount = " + jcount);
    
            // Count implementation at my Order
            if (jcount < 1) {
                alertShow();
            } else {
                intiliazeOrderListDialog();
                showOrderListDialog();
            }
    
            // startActivity(new Intent(RestaurantHome.this,
            // MyOrderList.class));
    
        }