Why is it that when I have two edit text boxes - (one calls a date dialog and the other calls a time dialog). why do I have to press twice for the dialog to open. the first press focuses it then the second press opens the dialog for it.

How do I make it that when I press the edit-text box then the dialog opens on the first press

**Java coding**

```
public class MainActivity extends Activity {

int hour = -1, min = -1;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // ////TIME picker
    EditText etOne = (EditText) findViewById(R.id.editText1);
    etOne.setOnClickListener(new EditText.OnClickListener() {
        public void onClick(View v) {
            // Do stuff here
            if (hour == -1 || min == -1) {
                Calendar c = Calendar.getInstance();
                hour = c.get(Calendar.HOUR);
                min = c.get(Calendar.MINUTE);
            }

            showTimeDialog(v, hour, min);
        }
    });

    // ////////////////////////////////////////////////////

    // //////////////////////////date picker

    EditText ettwo = (EditText) findViewById(R.id.editText2);

    ettwo.setOnClickListener(new EditText.OnClickListener() {
        public void onClick(View v) {
            // Do stuff here

            Calendar c = Calendar.getInstance();
            int day = c.get(Calendar.DAY_OF_MONTH);
            int month = c.get(Calendar.MONTH);
            int year = c.get(Calendar.YEAR);

            showDateDialog(v, day, month, year);
        }

    });

    // ///////////////////////////////////////////////

}

// ////TIME picker
public void showTimeDialog(View v, int hour, int min) {
    (new TimePickerDialog(this, timeSetListener, hour, min, true)).show();
}

public TimePickerDialog.OnTimeSetListener timeSetListener = new TimePickerDialog.OnTimeSetListener() {

    @Override
    public void onTimeSet(TimePicker view, int hourOfDay, int minute) {

        hour = hourOfDay;
        min = minute;
        EditText et = (EditText) findViewById(R.id.editText1);
        et.setText(hour + " : " + min);

    }

};

// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

private void showDateDialog(View v, int day, int month, int year) {
    // TODO Auto-generated method stub

    (new DatePickerDialog(MainActivity.this, dateSetListener, year, month,
            day)).show();
}

public DatePickerDialog.OnDateSetListener dateSetListener = new DatePickerDialog.OnDateSetListener() {

    @Override
    public void onDateSet(DatePicker view, int year, int monthOfYear,
            int dayOfMonth) {
        // TODO Auto-generated method stub

        EditText et = (EditText) findViewById(R.id.editText2);
        et.setText(dayOfMonth + "/" + monthOfYear + "/" + year);

    }
};
}

```

**XML Coding**

```
<?xml version="1.0" encoding="utf-8"?>

```

```
<EditText
    android:id="@+id/editText1"
    android:layout_width="300dp"
    android:layout_height="30dp"
    android:layout_gravity="left"
    android:background="#999999"
    android:gravity="left" />

<EditText
    android:id="@+id/editText2"
    android:layout_width="300dp"
    android:layout_height="30dp"
    android:layout_gravity="left"
    android:background="#998899"
    android:gravity="left" />

```