Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
183 views
in Technique[技术] by (71.8m points)

android - TextView and Button in each row and onListItemClick()

I have a ListView with some elements on it. Each row has a TextView and a Button. It looks like this:

| Some text in a row (Button) |

Now, when I click on this text nothing happens. Simply no one function is called. But when I click on the button I can handle the event. I use onListItemClick()

So what should I use instead of this TextView to be able to handle an event (when I click on the text)?

Before this I had only one TextView in each row and when I was clicking on a row everything worked fine (onListItemClick() was called).

Thank you in advance!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

add the property focusable="false" to your TextView ::

<TextView
...
...
        android:focusable="false"
        />

and probably you will need to do the same to the other elements inside your ListView.


Programatically we can use the method setFocusable():

v.findViewById(R.id.my_button).setFocusable(false); 

setFocusable(): Setting this to false will also ensure that this view is not focusable in touch mode.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...