国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Android > 正文

Android 中ListView點擊Item無響應問題的解決辦法

2019-12-12 04:17:06
字體:
來源:轉載
供稿:網友

如果listitem里面包括button或者checkbox等控件,默認情況下listitem會失去焦點,導致無法響應item的事件,最常用的解決辦法是在listitem的布局文件中設置descendantFocusability屬性。

item的布局文件:

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout  xmlns:android="http://schemas.android.com/apk/res/android"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:paddingTop="10dp"  android:paddingBottom="10dp"  android:paddingLeft="5dp"  android:paddingRight="5dp"  android:descendantFocusability="blocksDescendants"><!--添加這個屬性-->  <CheckBox  android:id="@+id/history_item_checkbt"  android:layout_height="30dp"  android:layout_width="wrap_content"  android:layout_centerVertical="true"  android:layout_alignParentLeft="true"  android:checked="false"  >  </CheckBox>  <ImageView  android:id="@+id/history_item_image"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_centerVertical="true"  android:layout_toRightOf="@id/history_item_checkbt"  android:background="@drawable/item_icon">  </ImageView>  <Button  android:id="@+id/history_item_edit_bt"  android:layout_alignParentRight="true"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_centerVertical="true"  android:text="編輯"  android:textColor="#ffffff"  android:textSize="14sp"  android:background="@drawable/button_bg">  </Button>  <TextView  android:id="@+id/history_item_time_tv"  android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:layout_centerVertical="true"  android:textColor="#565C5D"  android:textSize="14sp"  android:text="10-01 10:20"  android:layout_marginRight="5dp"  android:layout_toLeftOf="@id/history_item_edit_bt">  </TextView>  <TextView  android:id="@+id/history_item_title_tv"  android:layout_height="wrap_content"  android:layout_width="fill_parent"  android:layout_centerVertical="true"  android:textColor="#565C5D"  android:textSize="14sp"  android:text="xxxxxxxxXXXXXXXXXXXXXXXX"  android:ellipsize="end"  android:maxLines="1"  android:layout_toRightOf="@id/history_item_image"  android:layout_toLeftOf="@id/history_item_time_tv"  android:layout_marginLeft="3dp">  </TextView> </RelativeLayout> 

android:descendantFocusability

Defines the relationship between the ViewGroup and its descendants when looking for a View to take focus.

Must be one of the following constant values.

該屬性是當一個為view獲取焦點時,定義viewGroup和其子控件兩者之間的關系。

屬性的值有三種:

        beforeDescendants:viewgroup會優先其子類控件而獲取到焦點

        afterDescendants:viewgroup只有當其子類控件不需要獲取焦點時才獲取焦點

        blocksDescendants:viewgroup會覆蓋子類控件而直接獲得焦點

  我們使用的是第三個。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 柘城县| 临邑县| 广安市| 阿图什市| 呼图壁县| 清丰县| 金寨县| 化隆| 滁州市| 东乡族自治县| 永胜县| 海晏县| 鄂托克旗| 盐边县| 冕宁县| 洪雅县| 湖南省| 中江县| 盘山县| 永靖县| 都江堰市| 普兰店市| 临夏市| 吐鲁番市| 洞口县| 唐山市| 双峰县| 宁蒗| 遂宁市| 三河市| 温州市| 南安市| 化隆| 绿春县| 永州市| 郑州市| 中阳县| 潼南县| 焉耆| 沙洋县| 黄山市|