onClick时如何对话不关闭

时间:2013-07-30 20:29:31

标签: android dialog

我有一个使用对话框的活动。但是,当我单击对话框时,控件值和对话框将关闭。单击对话框时如何才能关闭对话框?

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

2 个答案:

答案 0 :(得分:0)

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

有关
public void onClick(DialogInterface dialog, int which) {
            removeDialog(EKLE);

答案 1 :(得分: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();
}