* 原來在代碼中多了這個。百思不得騎姐
*以前是被代碼直接覆蓋住了子控件的焦點因此edittext不能拿到焦點
* android:descendantFocusability="blocksDescendants" //會覆蓋子類控件而直接得到焦點 android:focusable="false"
* 常常父控件子控件都須要焦點的時候設置第一條屬性,而後子控件在代碼在主動要求獲取焦點
* android:descendantFocusability="beforeDescendants" //會優先其子類控件而獲取到焦點
* android:descendantFocusability="afterDescendants" //只有當其子類控件不須要獲取焦點時才獲取焦點
* android:descendantFocusability="blocksDescendants"android
ListView widget,在ListView中加入Button這類的有 「點擊」 事件的widget,發現原來listview的itemclick竟然失效了,ListView 和 其它能觸發點擊事件的widget沒法一塊兒正常工做的緣由是加入其它widget後,ListView的itemclick事件將沒法觸發,被其它widget的click事件屏蔽。佈局
解決辦法:spa
在item中,包含button的item的Layout中加入屬性 android:descendantFocusability= "blocksDescendants"xml
在buttion的屬性加入android:focusable="false"繼承
問題解決,兩個click事件再也不衝突了!事件
====================ip
ListView的setOnItemClickListener事件和ListView中Item中包含的子控件(好比button)的click事件共存的解決辦法:
在ListView的item的xml配置文件的根節點添加屬性
android:descendantFocusability="blocksDescendants",
而且,在要添加事件的子控件(如button)的屬性裏添加android:focusable="false"
另外,注意:有時現成的幾個adapter知足不了要求,此時就須要繼承自BaseAdapter。
下面我是程序中的部分代碼,該佈局文件時listview中的item的佈局,
listview_listitem_layout.xml 代碼以下:get
<RelativeLayoutit
xmlns:android="http://schemas.android.com/apk/res/android"io
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:descendantFocusability="blocksDescendants"
style="@style/ListItem">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<ImageView
android:layout_width="45dip"
android:layout_height="45dip"
android:layout_gravity="center"
android:layout_alignParentLeft="true"
android:background="@drawable/imageview_background"
android:scaleType="fitXY" />
<Button
android:layout_width="@dimen/btn_attention_width"
android:layout_height="@dimen/btn_attention_height"
android:layout_alignParentRight="true"
android:background="@drawable/button_selector_gradient"
android:text="關注"
android:focusable="false"/>
</RelativeLayout>