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

Android 中ListView點(diǎn)擊Item無響應(yīng)問題的解決辦法

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

如果listitem里面包括button或者checkbox等控件,默認(rèn)情況下listitem會失去焦點(diǎn),導(dǎo)致無法響應(yīng)item的事件,最常用的解決辦法是在listitem的布局文件中設(shè)置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.

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

屬性的值有三種:

        beforeDescendants:viewgroup會優(yōu)先其子類控件而獲取到焦點(diǎn)

        afterDescendants:viewgroup只有當(dāng)其子類控件不需要獲取焦點(diǎn)時才獲取焦點(diǎn)

        blocksDescendants:viewgroup會覆蓋子類控件而直接獲得焦點(diǎn)

  我們使用的是第三個。

相關(guān)文章

  • Android自定義鐘表特效

    Android自定義鐘表特效

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

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

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

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

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

    Android UI效果之繪圖篇(一)

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

    Android控件AppWidgetProvider使用方法詳解

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

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

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

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

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

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

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

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

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

    一文詳解如何在Flutter中使用導(dǎo)航Navigator

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

最新評論