search

Home  >  Q&A  >  body text

android - Button设置了focusable="false",还怎么监听到事件?

由于使用了onItemClickListener,存在Button的时候ListView不能监听到点击事件,所以对Button做了如下处理

    android:focusable="false"
    android:focusableInTouchMode="true"

对Button的父类容器做这样的处理

    android:descendantFocusability="blocksDescendants"

之前的ListView监听问题解决了
但是,不知道后续应该怎么做了,我想在button上也添加事件,但是我理解的状态是:目前不能添加事件了,我理解的对不对,请各位大神指教

黄舟黄舟2771 days ago565

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-04-18 09:17:19

    Do not use the onItemClick event provided by ListView.
    Register the onClick event when initializing ItemView.
    Then register the onClick event for Button.

    reply
    0
  • 怪我咯

    怪我咯2017-04-18 09:17:19

    Your understanding is wrong.

    ListViewItemViewIf any focusable View is used, the click event of ItemView will be intercepted by that type of View. To solve this problem, you only need to set the following attributes to RootView in layout-xml to solve the above problem:

    android:descendantFocusability="blocksDescendants"
    

    It would be nice if you still want to give ItemViewChildView设置OnClickListener, 那就直接调用View.setOnClickListener(OnClickListener).

    reply
    0
  • Cancelreply