Clear text in EditText when entered

后端 未结 18 1586
醉话见心
醉话见心 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:44

    It's simple: declare the widget variables (editText, textView, button etc.) in class but initialize it in onCreate after setContentView.

    The problem is when you try to access a widget of a layout first you have to declare the layout. Declaring the layout is setContentView. And when you initialize the widget variable via findViewById you are accessing the id of the widget in the main layout in the setContentView.

    I hope you get it!

提交回复
热议问题