Android Row becomes Unclickable with button

I have a listView where each row has a button in the row layout. However, this seems to make the string the most unattractive. How can I make the button and row pressed?

Thank.

+18
java android
Feb 23 2018-10-23T00
source share
4 answers

You need to set itemsCanFocus in the list as follows:

mList.setItemsCanFocus(true); 

So that the button is pressed. Then you will need to use your own adapter, and in getView return a view that is Clickable and customizable. You will also lose the default backlight states, so you need to return them back to the background resource. So do this:

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

before returning your submission.

+25
Feb 24 '10 at 1:41
source share
— -

Whenever I see messages about the android:focusable and android:clickable attributes, I always see that they are set to the same values ​​at the same time. I decided that there should be a reason if they are two separate attributes, not one.

It turns out that a much better way to achieve the desired behavior is to establish

 android:focusable="false" 

or

 yourButton.setFocusable(false) 

on Button in View . Once you do this, you can set OnClickListener to Button , and clicking on a line will trigger the onListItemClick() method in OnItemClickListener .

+9
Jun 14 '13 at 7:38
source share

Try to set your widgets to without clickable and inactive in xml, clicking on the elements will work fine, and the click button will work fine.

 android:clickable="false" android:focusable="false" 

Hope this helps.

+2
Nov 02
source share

Unfortunately, I do not think this is possible. A ListView string can have either custom widgets, a button, or a click, and not both. See link.

0
Feb 24 2018-10-12T00
source share



All Articles