欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時間:2016年12月20日 09:20:28   作者:huaxaY  
如果listitem里面包括button或者checkbox等控件,默認情況下listitem會失去焦點,導致無法響應item的事件,怎么解決呢?下面小編給大家分享下listview點擊item無響應的解決辦法

如果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會優(yōu)先其子類控件而獲取到焦點

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

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

  我們使用的是第三個。

相關文章

  • Android自定義鐘表特效

    Android自定義鐘表特效

    這篇文章主要為大家詳細介紹了Android自定義鐘表特效,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-12-12
  • Android顯式Intent與隱式Intent的使用詳解

    Android顯式Intent與隱式Intent的使用詳解

    Intent的中文意思是“意圖,意向”, Intent對Android的核心和靈魂,是各組件之間的橋梁。四大組件分別為Activity 、Service、BroadcastReceiver、ContentProvider。而這四種組件是獨立的,它們之間可以互相調(diào)用,協(xié)調(diào)工作,最終組成一個真正的Android應用
    2022-09-09
  • Android數(shù)據(jù)持久化之File機制分析

    Android數(shù)據(jù)持久化之File機制分析

    這篇文章主要介紹了Android數(shù)據(jù)持久化之File機制,較為詳細的分析了File機制的原理及Android使用File實現(xiàn)數(shù)據(jù)持久化的相關操作技巧,需要的朋友可以參考下
    2017-05-05
  • Android UI效果之繪圖篇(一)

    Android UI效果之繪圖篇(一)

    這篇文章主要介紹了Android UI效果之繪圖篇,針對Android開發(fā)中的UI效果設計模塊進行講解,感興趣的小伙伴們可以參考一下
    2016-02-02
  • Android控件AppWidgetProvider使用方法詳解

    Android控件AppWidgetProvider使用方法詳解

    這篇文章主要為大家詳細介紹了Android控件AppWidgetProvider的使用方法詳解,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • Android判斷App前臺運行還是后臺運行(運行狀態(tài))

    Android判斷App前臺運行還是后臺運行(運行狀態(tài))

    這篇文章主要介紹了Android判斷App前臺運行還是后臺運行的相關資料,需要的朋友可以參考下
    2016-04-04
  • Android形狀圖形與狀態(tài)列表圖形及九宮格圖片超詳細講解

    Android形狀圖形與狀態(tài)列表圖形及九宮格圖片超詳細講解

    這篇文章主要介紹了Android形狀圖形與狀態(tài)列表圖形及九宮格圖片的應用方法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧
    2022-09-09
  • Android異步消息處理機制實現(xiàn)原理詳解

    Android異步消息處理機制實現(xiàn)原理詳解

    這篇文章主要介紹了Android異步消息處理機制實現(xiàn)原理詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2020-09-09
  • Android實現(xiàn)單頁顯示3個Item的ViewPager炫酷切換效果

    Android實現(xiàn)單頁顯示3個Item的ViewPager炫酷切換效果

    這篇文章主要為大家詳細介紹了Android實現(xiàn)單頁顯示3個Item的ViewPager炫酷切換效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-10-10
  • 一文詳解如何在Flutter中使用導航Navigator

    一文詳解如何在Flutter中使用導航Navigator

    一個APP如果沒有頁面跳轉那么是沒有靈魂的,頁面跳轉的一個常用說法就是Navigator。那么在flutter中如何使用Navigator呢?本文就來和大家詳細聊聊
    2023-02-02

最新評論