Android Custom Dialog Display

231 views Asked by At

My custom dialog layout has 2 edit text fields.

<EditText
    android:id="@+id/e2"
    android:inputType="none"
    android:longClickable="false"
    android:selectAllOnFocus="true"
    android:textIsSelectable="true" />

<EditText
    android:id="@+id/e2"
    android:inputType="none"
    android:longClickable="false"
    android:selectAllOnFocus="true"
    android:textIsSelectable="true" />

I implement my class using OnFocusChangeListener.

My idea is when I click the text field, one custom popup dialog appears to select my pre-defined value.

It work correctly but I have a minor problem.

If I click the editext 1 => dialog apear (I select the button then it dismisses) => click editext 2 => dialig appear (I select the button then it dismisses).

However, if If I click the editext 1 => dialog appears (I select the button then it dismisses), then I click on editext 1 immediately again (even many times I try), my dialog does not show up (In expectation, it should appear whenever I click).

My Class

public class user_input extends Activity implements OnFocusChangeListener {
@Override
public void onFocusChange(View v, boolean hasFocus) {

    final EditText edt = (EditText) findViewById(v.getId());

    if (hasFocus) {

        final Dialog dialog = new Dialog(user_input.this);
        dialog.setContentView(R.layout.input_dialog);
        dialog.setTitle("SELECT A NUMBER: ");
        dialog.show();

        btn1 = (Button) dialog.findViewById(R.id.val1);
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                edt.setText("1");
                dialog.cancel();
            }
        });

        btn2 = (Button) dialog.findViewById(R.id.val2);
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                edt.setText("2");
                dialog.cancel();
            }
        });
      }
}

How to show it as my expectation? Thank you very much in advanced.

0

There are 0 answers