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
329 views
in Technique[技术] by (71.8m points)

android - Using Spinner in a List Item does not trigger the OnItemClik

I have a ListView in which each List item has a Spinner. I have successfully added an OnItemSelectedListener to each spinner by implementing OnItemSelectedListener in the Activity and adding it in the GetView() of the adapter.

The problem is, I also have to implement OnItemClickListener for the ListView in the Activity. I have done that, but the event is not getting fired for the Item Click on normal list items. But, it is getting fired for the list section headers(which do not have the spinners).

How can I trigger the event for the List items as well?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Try this,

add the below property to your Spinner element,

android:focusable=false

The problem is because spinner is a element with clickable property, which will take the control of your click events and hence your listview wont get the chance to handle the click events. By adding the above property you can make both the spinner and your listview to get worked.

If it still doesn't work then try adding this to the top most layout of your listview element xml ,

android:descendantFocussability=blocksDescendants 

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

...