Clear text in EditText when entered

后端 未结 18 1683
醉话见心
醉话见心 2020-11-27 03:44

I\'m trying to set and onclicklistener so that when I click within the edittext element it will clear its current contents. Is there something wrong here? When I compile thi

18条回答
  •  误落风尘
    2020-11-27 04:47

    You can use the 'android:hint' attribute in your EditText also from code:

    editText.setHint(CharSequence hint / int resid);
    

    Then you don't need any onClickListener or similar. But consider that the hint value won't be passed. The editText will be stayed empty. In this case you can set your editText with your deflault value:

    if(editText.getText().toString().equals("")) { 
    ...use your default value instead of the editText... }
    

提交回复
热议问题