Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
188 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...