Single click edittext

How to make EditText have an onClick event so that with a single click the action is executed.

private void addListenerOnButton() {

        dateChanger = (EditText) findViewById(R.id.date_iWant);

        dateChanger.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                showDialog(DATE_DIALOG_ID);
            }
        });
    }

this does not work as excluded .... one click gives only the on-screen keyboard, but not the datepicker dialog, which appears only if I double-clicked

+3
source share
4 answers

if we just add android:focusableInTouchMode="false"to the edittext on the layout page, it should work in singleclick on its onclicklistener. no need to handle onFocusChangeListener.

+9
source

Rewrite

I have an EditText that launches a dialog box when the user either clicks it once or moves to it using the trackball / guide panel. I use this approach:

  • OnFocusChangeListener , .
  • offsetDialog(), EditText, , ( ) .

( , ):

  • OnClickListener .
  • setFocusable(false), .

, .

0

onClickListener OnFocusChangeListener.

private void addListenerOnButton() {

    dateChanger = (EditText) findViewById(R.id.date_iWant);

    dateChanger.setOnFocusChangeListener(new OnFocusChangeListener() {

        public void onFocusChange(View v, boolean hasFocus) {
            if(hasFocus) {
                showDialog(DATE_DIALOG_ID);
            }
        }
    });
}
0

EditText singleClick.

, Click Listener . , ,

onFocusChangeListener, 100% .

EditText TextView onClick TextView.


enter image description here

0

All Articles