Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextView onClick not responding to single tap

Tags:

android

I have a TextView with the following assignment code:

Answer1TextView = (TextView) findViewById(R.id.editText1);
Answer1TextView.setOnClickListener(answer1TextViewListener);

and here is my onClickListener:

private  OnClickListener answer1TextViewListener = new OnClickListener() 
{
    public void onClick(View v) 
    {
        if(Answer1Win){
            Toast.makeText(QuizScreen.this,"Correct ",2).show();
        } else
        {
            Toast.makeText(QuizScreen.this,"Incorrect, Pick Another Answer",2).show();
        }
    }
};  

My problem is the Toast only is displayed after a double tap. I cannot find a setting the drives this behavior, what could be set wrong to not display after a single tap.

like image 528
Trey Balut Avatar asked Nov 30 '11 20:11

Trey Balut


3 Answers

The first click just sets the focus to the TextBox then the second click actually gets handled as a click. Rather than using an onClickListener, you may have better luck with an onFocusChangeListener

like image 84
Chris Avatar answered Nov 08 '22 09:11

Chris


As Chris said, the first tap focuses the TextView and the second tap clicks it.

Setting android:focusableInTouchMode="false" fixes the problem for touchscreens but without breaking functionality for non-touchscreen devices.

If you were to simply use android:focusable="false" that would prevent, for example, d-pad users from clicking the view at all.

like image 30
just me Avatar answered Nov 08 '22 09:11

just me


The issue may be that textIsSelectable is true. Set textIsSelectable="false" for the TextView in XML.

like image 2
Ryan Muller Avatar answered Nov 08 '22 07:11

Ryan Muller