Clear text in EditText when entered

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

    //To clear When Clear Button is Clicked

    firstName = (EditText) findViewById(R.id.firstName);

        clear = (Button) findViewById(R.id.clearsearchSubmit);
    
        clear.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                if (v.getId() == R.id.clearsearchSubmit);
                firstName.setText("");
            }
        });
    

    This will help to clear the wrong keywords that you have typed in so instead of pressing backspace again and again you can simply click the button to clear everything.It Worked For me. Hope It Helps

提交回复
热议问题