0

我有一个使用对话框的活动。但是,当我单击对话框时,控制值并关闭对话框。单击对话框时如何不关闭对话框?

private Dialog ekleDialog(){

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    View layout = LayoutInflater.from(this).inflate(R.layout.dialog_ekle, null);

    builder.setTitle(R.string.ekleAction);
    builder.setView(layout);

    final EditText tutarEdit = (EditText) layout.findViewById(R.id.editTextTutar);
    final EditText aciklamaEdit = (EditText) layout.findViewById(R.id.editTextAciklama);

    final RadioButton gelirRadio = (RadioButton) layout.findViewById(R.id.radioGelir);
    final RadioButton giderRadio = (RadioButton) layout.findViewById(R.id.radioGider);

    builder.setNegativeButton(R.string.dialogCancel, new DialogInterface.OnClickListener() {

        @SuppressWarnings("deprecation")
        @Override
        public void onClick(DialogInterface dialog, int which) {
            removeDialog(EKLE);

        }
    });

    builder.setPositiveButton(R.string.dialogKaydet, new DialogInterface.OnClickListener() {

        @SuppressWarnings("deprecation")
        @Override
        public void onClick(DialogInterface dialog, int which) {

            float tutar = Float.parseFloat(tutarEdit.getText().toString());
            String aciklama = aciklamaEdit.getText().toString();  

                if(tutarEdit.getText().toString().equals("") || aciklamaEdit.getText().toString().equals("")){
                    Toast.makeText(MainActivity.this, R.string.toastMesaj, Toast.LENGTH_LONG).show();
                **Dialog not close !**      
                }else{
                    ekleGelir(tutar, aciklama);
                    removeDialog(EKLE);
                    dialog.dismiss();
                }
            }
    });

    builder.setCancelable(true);
    return builder.create();
}
4

2 回答 2

0

只是在这里猜测一下,但它可能与:

public void onClick(DialogInterface dialog, int which) {
            removeDialog(EKLE);
于 2013-07-30T20:32:53.327 回答
0

您有一个根本不会关闭对话框的代码路径。尝试改变它

public void onClick(DialogInterface dialog, int which) {

        float tutar = Float.parseFloat(tutarEdit.getText().toString());
        String aciklama = aciklamaEdit.getText().toString();  

        if(tutarEdit.getText().toString().equals("") || aciklamaEdit.getText().toString().equals("")){
                Toast.makeText(MainActivity.this, R.string.toastMesaj, Toast.LENGTH_LONG).show();
        }else{
                ekleGelir(tutar, aciklama);
                removeDialog(EKLE);
        }            
        dialog.dismiss();
}
于 2013-07-30T20:39:01.373 回答