随笔-348  评论-598  文章-0  trackbacks-0
将具有点击事件控件的android:focusable属性置成false就可以了。如下例子是可以既捕捉onItemClick事件(在非checkbox和非button区域),又可以捕捉onClick等事件。看到网上还有很多人不会,特意共享一下。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation
="horizontal" android:layout_height="fill_parent"
    android:id
="@+id/LinearLayoutGameListItem" android:layout_width="fill_parent"
    android:gravity
="center_vertical" android:layout_marginLeft="@dimen/mygamecenter_common_margin"
    android:layout_marginRight
="@dimen/mygamecenter_common_margin">
<CheckBox android:id="@+id/CheckBoxGameListItem"
            android:focusable
="false" android:layout_width="wrap_content"
            android:layout_height
="wrap_content"></CheckBox>
    
<Button android:text="@string/top" android:id="@+id/ButtonTop"
        android:textColor
="#FFFFFF" android:focusable="false"
        android:layout_width
="wrap_content" android:layout_height="@dimen/game_list_item_button_height"
        android:layout_marginRight
="@dimen/game_list_item_button_margin_right"
        android:paddingLeft
="@dimen/game_list_item_button_padding_left"
        android:paddingRight
="@dimen/game_list_item_button_padding_right"
android:background
="@drawable/button_cool_small_selector"></Button>
</LinearLayout>


---------------------------------------------------------
专注移动开发

Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
posted on 2010-10-13 21:16 TiGERTiAN 阅读(4995) 评论(2)  编辑  收藏 所属分类: Android

评论:
# re: Android/OPhone ListView中如何使用Button,让onClick和onItemClick事件共存 2012-09-14 16:53 | zealotrouge
Button验证OK,但是ImageButton用此方法还是不行哦~  回复  更多评论
  
# re: Android/OPhone ListView中如何使用Button,让onClick和onItemClick事件共存[未登录] 2013-06-13 11:17 | 啊啊

只有注册用户登录后才能发表评论。


网站导航: