EditText onClickListener in Android

后端 未结 14 2130
时光取名叫无心
时光取名叫无心 2020-12-02 12:03

I want an EditText which creates a DatePicker when is pressed. So I write the following code:

    mEditInit = (EditText) findViewById(R.id.date_init);
    mE         


        
14条回答
  •  我在风中等你
    2020-12-02 12:17

    The keyboard seems to pop up when the EditText gains focus. To prevent this, set focusable to false:

    
    

    This behavior can vary on different manufacturers' Android OS flavors, but on the devices I've tested I have found this to to be sufficient. If the keyboard still pops up, using hints instead of text seems to help as well:

    myEditText.setText("My text");    // instead of this...
    myEditText.setHint("My text");    // try this
    

    Once you've done this, your on click listener should work as desired:

    myEditText.setOnClickListener(new OnClickListener() {...});
    

提交回复
热议问题