最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義ListView單擊事件失效的解決方法

 更新時間:2018年07月26日 15:12:10   作者:_York  
這篇文章主要為大家詳細介紹了Android自定義ListView單擊事件失效的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下

因為自帶的listView不能滿足項目需求,通過實現(xiàn)自己的Adapter去繼承ArrayAdapter 來實現(xiàn)自定義ListView的Item項目。

出現(xiàn)點擊ListView的每一項都不會執(zhí)行setOnItemClickListener 里面的onItemClick 方法。

原因是item里面存在一些子控件,默認點擊獲取的焦點跑去子控件去了,點擊失效。

解決辦法:

在item的根目錄加入android:descendantFocusability="blocksDescendants"

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:descendantFocusability="blocksDescendants">

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:padding="5dp">


    <ImageView
      android:id="@+id/imageView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      app:srcCompat="@drawable/message_oc" />

    <TextView
      android:id="@+id/textTitle"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="title"
      android:textSize="25dp"
      android:layout_marginLeft="15dp"/>

    <TextView
      android:id="@+id/textDate"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:gravity="right"
      android:text="date" />
  </LinearLayout>

  <LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView
      android:id="@+id/textMessage"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:ems="10"
      android:inputType="textMultiLine"
      android:text="message"
      android:textSize="20dp"/>
  </LinearLayout>

</LinearLayout>

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

屬性的值有三種:

  •         beforeDescendants:viewgroup會優(yōu)先其子類控件而獲取到焦點
  •         afterDescendants:viewgroup只有當其子類控件不需要獲取焦點時才獲取焦點
  •         blocksDescendants:viewgroup會覆蓋子類控件而直接獲得焦點

我們使用blocksDescendants 屬性來覆蓋子類控件,而直接獲取焦點。

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

彭阳县| 萝北县| 本溪| 澄迈县| 呼伦贝尔市| 道真| 长海县| 株洲市| 全州县| 玉溪市| 拉萨市| 登封市| 体育| 阿城市| 建宁县| 河东区| 娄烦县| 吉木乃县| 兰西县| 永登县| 洛扎县| 罗源县| 浮梁县| 汪清县| 四川省| 龙井市| 怀来县| 武夷山市| 合作市| 如东县| 普定县| 穆棱市| 于田县| 洛隆县| 乡宁县| 子长县| 合江县| 莎车县| 朝阳市| 禄丰县| 南昌市|