AlertDialog一直关闭PositiveButton点击

时间:2018-04-19 09:58:29

标签: android dialog alert

当我按下上一个按钮时,我正在弹出警报对话框      布局。在保存之前我需要输入3个文本字段       data.the代码应该这样工作:如果一个文本字段为空,Toast       弹出并提供文本字段为空的信息,并且应填充数据。它还应该关注那个空的文本字段。现在,问题是,当我点击positiveButton并尝试保存我的数据(甚至我的文本字段为空)时,警报对话框关闭,只有Toast会发出警告,表示文本字段为空并且警告对话框已删除。我提供的代码可以进行警告对话,如果有人能理解我并帮助我,我会尝试提供更多信息:D

final View view1 = LayoutInflater.from(dezurniTelefon_Activity.this).inflate(R.layout.tiket_layout, null);

final EditText EtUzrokProb = (EditText) view1.findViewById(R.id.textViewTiket1);
final EditText EtResenjeProb = (EditText) view1.findViewById(R.id.textViewTiket2);
final EditText EtVremeTrajanja = (EditText) view1.findViewById(R.id.textViewTiket3);

final AlertDialog d1 = new AlertDialog.Builder(dezurniTelefon_Activity.this)
     .setTitle("Tiket: " + IdTiketa   )
     .setPositiveButton("Sačuvaj", new DialogInterface.OnClickListener() {
     @Override
     public void onClick(DialogInterface dialog, int which)
     {

        String stringUzrok = EtUzrokProb.getText().toString();
        String stringResenje = EtResenjeProb.getText().toString();
        String stringVremeTrajanja = EtVremeTrajanja.getText().toString();
        if (stringUzrok.matches("")  )
            {
             // Toast.makeText(dezurniTelefon_Activity.this, "Unesite uzrok problema", Toast.LENGTH_SHORT).show();
                                                        //EtUzrokProb.requestFocus();
                                                        //  return;

                                                    }
        if (stringResenje.matches("") )                                                        
           {  
              Toast.makeText(dezurniTelefon_Activity.this, "Unesite resenje problema", Toast.LENGTH_SHORT).show();
             }
        if (stringVremeTrajanja.matches("") )
        {                                                      
           Toast.makeText(dezurniTelefon_Activity.this, "Unesite vreme trajanja intervencije", Toast.LENGTH_SHORT).show();
         }
          }
       }).setView(view1)
       .setMessage("Firma: " +strNazFir + "\n" + "Vreme: " + vrmStrt)
       .setNegativeButton("Izađi", null)
       .setCancelable(false)
        .show();

                                }


   }).setNegativeButton("Izlaz", null)
     .setNeutralButton("Pozovi", new DialogInterface.OnClickListener()
     {
      @Override
      public void onClick(DialogInterface dialog, int which) {
             Uri number = Uri.parse("tel:" + strBrojTel);
             Intent callIntent = new Intent(Intent.ACTION_DIAL, number);
                            startActivity(callIntent);
                        }

                    }).show();

2 个答案:

答案 0 :(得分:3)

  

当用户触摸使用创建的任何操作按钮时   AlertDialog.Builder,系统为你解开对话框。

正如https://developer.android.com/guide/topics/ui/dialogs.html

所写

答案 1 :(得分:0)

创建自定义对话框。如文档中所述,这是默认的对话框行为。试试下面的代码。

public void popUpWindow() {

        final Dialog dialog = new Dialog(context, 
        android.R.style.Theme_Translucent_NoTitleBar);
        dialog.setContentView(R.layout.your_custom_layout);
        dialog.setCancelable(false);
        dialog.show();

        Button okBt=(Button)dialog.findViewById(R.id.ok_bt);
        Button cancelBt=(Button)dialog.findViewById(R.id.cancel_bt);

        okBt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              // do your validation here
              dialog.dismiss();// dismiss your dialog after doing stuff
            }
        });

        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                dialog.dismiss();// dismiss your dialog

            }
        });


}