关闭警报对话框

时间:2020-11-01 14:28:15

标签: android android-studio

单击Cancel按钮的“关闭警报”对话框不起作用。 Dismiss()Alert/dialog不起作用。请建议在Onclick按钮事件中写什么。

 @Override
            public void onClick(View v) {
           // Toast toast=Toast.makeText(getActivity(), "Enter number of households here", Toast.LENGTH_SHORT);


           final ViewGroup subview=(ViewGroup) getLayoutInflater().
                             inflate(R.layout.edittext_info_dialog,null,false) ;
           TextView tv = (TextView) subview.findViewById(R.id.Info_Title);
           tv.setText("Enter number of household in village here");

           final AlertDialog.Builder builder=  new AlertDialog.Builder(getContext());


                  builder.setView(subview);
                  builder .show();

                  

          Button Cancel=(Button) subview.findViewById(R.id.Cancel_Info);
          Cancel.setOnClickListener(new View.OnClickListener() {
              

              @Override
              public void onClick(View v) {
               Toast.makeText(getContext(),"Cancel",Toast.LENGTH_LONG).show();
               
              }
          });

            }
        });

1 个答案:

答案 0 :(得分:0)

您,不是建设者解雇

首先,更改行代码

   final AlertDialog builder=  new AlertDialog.Builder(getContext()).create();

您可以dismisscancel对话框

  @Override
     public void onClick(View v) {
         Toast.makeText(getc.this,"Cancel",Toast.LENGTH_LONG).show();
         builder.dismiss();
      }