Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OnClickListener listens only on the second time

I have an editText and have added an onClickListener to it. In the click method I am just clearing the text. When I click the editText first time the keypad pops up. But it is not going into the onClick method. The second time when I click it it is called and clears the text.

qtyEditTxt=(EditText)findViewById(R.id.qtyet);
qtyEditTxt.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                qtyEditTxt.setText("");             
            }
        });

I saw a question with an answer stating to make android:focusableInTouchMode to false. But then I will not be able to enter the text. Kindly help me with this

like image 315
SurRam Avatar asked Feb 23 '23 05:02

SurRam


1 Answers

How about focus?

final EditText qtyEditTxt= (EditText) findViewById(R.id.qtyet);
qtyEditTxt.setOnFocusChangeListener(new OnFocusChangeListener()
{
    @Override
    public void onFocusChange(View v, boolean isFocus) 
    {
        if (isFocus)
        {
            qtyEditTxt.setText("");             
        }
    }
});

Edited:

Default text? There you go :)

android:hint="Enter Quantity"
like image 127
Pete Houston Avatar answered Mar 03 '23 11:03

Pete Houston