【问题标题】:Dismiss() not working for Customize AlertDialogDismiss() 不适用于自定义 AlertDialog
【发布时间】:2013-11-05 09:03:42
【问题描述】:

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

 intiliazeOrderListDialog();
 showOrderListDialog();

我的声明如下

public AlertDialog detailsDialog, orderDialog;
AlertDialog.Builder builder;

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

    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();

不适合我。?在此先感谢大家。

【问题讨论】:

  • 它不会关闭对话框,因为在您的方法中它无法获得 orderDialog 的确切实例。
  • 感谢...您的回复。但是你能解释一下吗?你的小帮助对我来说意义重大。
  • 为什么你创建了这个方法showOrderListDialog()?你在哪里使用它?虽然在您的 intiliazeOrderListDialog() 方法中您已经在膨胀布局,那么在 showOrderListDialog() 中再次传递布局有什么需要?
  • @GrIsHu...你的建议对我不起作用我仍然遇到同样的问题
  • 我还没有给出任何建议。

标签: android android-alertdialog dismiss


【解决方案1】:

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

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));

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-29
    • 2017-06-25
    • 2019-05-18
    • 2015-05-16
    • 2020-12-05
    相关资源
    最近更新 更多