Skip to content Skip to sidebar Skip to footer

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

Solution 1:

How about focus?

final EditText qtyEditTxt= (EditText) findViewById(R.id.qtyet);
qtyEditTxt.setOnFocusChangeListener(newOnFocusChangeListener()
{
    @OverridepublicvoidonFocusChange(View v, boolean isFocus) 
    {
        if (isFocus)
        {
            qtyEditTxt.setText("");             
        }
    }
});

Edited:

Default text? There you go :)

android:hint="Enter Quantity"

Solution 2:

Solution 3:

ClickListener is not a good choice for editText . use

editText.setOnEditorActionListener(new TextWatcher() {

            publicvoidonTextChanged(CharSequence s, int start, int before, int count) {
                // TODO Auto-generated method stub

            }

            publicvoidbeforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub

            }

            publicvoidafterTextChanged(Editable s) {
                // TODO Auto-generated method stub

            }
        })
    }

Post a Comment for "Onclicklistener Listens Only On The Second Time"