項目中的listview不僅僅是簡單的文字,常常需要自己定義listview,自己的Adapter去繼承BaseAdapter,在adapter中按照需求進行編寫,諸如ImageButton,Button,CheckBox等子控件(也可以說是Button或者Checkable的子類控件)此時這些子控件會將焦點獲取到,所以常常當點擊item時變化的是子控件,item本身的點擊沒有響應。
android:descendantFocusability
Defines therelationship between the ViewGroup and its descendants when looking for a Viewto take focus.
Must be oneof the following constant values.
該屬性是當一個爲view獲取焦點時,定義viewGroup和其子控件兩者之間的關係。
屬性的值有三種:
beforeDescendants:viewgroup會優先其子類控件而獲取到焦點
afterDescendants:viewgroup只有當其子類控件不需要獲取焦點時才獲取焦點
blocksDescendants:viewgroup會覆蓋子類控件而直接獲得焦點
至於用法麼,就是在item 裏的RelativeLayout 加入android:descendantFocusability=" blocksDescendants