歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> Android ListView嵌套Button,Button事件覆蓋item事件解決辦法

Android ListView嵌套Button,Button事件覆蓋item事件解決辦法

日期:2017/3/1 10:00:51   编辑:Linux編程

Android ListView嵌套Button,Button事件覆蓋item事件解決辦法

方法就是修改item布局的xml文件:

在根布局裡加上:

android:descendantFocusability="blocksDescendants"

然後在按鈕布局裡加上:

android:focusable="false"

item和按鈕都 可以點了,就OK了

下面是布局示例:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical"
  6. android:descendantFocusability="blocksDescendants"

  1. <Button
  2. android:id="@+id/worklog_update"
  3. android:layout_width="wrap_content"
  4. android:layout_height="wrap_content"
  5. android:text="修改"
  6. android:focusable="false"
  7. />
  8. <Button
  9. android:id="@+id/worklog_del"
  10. android:layout_width="wrap_content"
  11. android:layout_height="wrap_content"
  12. android:text="刪除"
  13. android:focusable="false"
  14. />

更多Android相關信息見Android 專題頁面 http://www.linuxidc.com/topicnews.aspx?tid=11

Copyright © Linux教程網 All Rights Reserved