Android Row becomes Unclickable with Button

前端 未结 4 2034
时光取名叫无心
时光取名叫无心 2020-12-01 03:23

I have a listView, where each row has a button in the row layout. However, this seems to make the row itself unclickable. How can I make both the button and row clickable? <

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 03:56

    You need to set itemsCanFocus on the list like this:

        mList.setItemsCanFocus(true);
    

    To make the button clickable. Then you will need to use your own adapter and in getView return a view which is Clickable and focusable. You will also lose the default highlight states so you need to put them back in with the background resource. So do this:

        view.setClickable(true);
        view.setFocusable(true);
        view.setBackgroundResource(android.R.drawable.menuitem_background);
    

    to your view before returning your view.

提交回复
热议问题