Button onClick and ListView onItemClick - android

I got a ListView and I populate it with the view containing buttons. I set onClick listeners to the buttons from the adapted, but when I click the concrete item of the ListView - nothing happens. So, we can say only buttons onClick Listener is called, when I need listViewItem to be clicked.
What to do?

Set to your button in xml file: android:focusable="false"
This is because your Button takes focus. So now you can use both onClick for your buttons, and onItemClick for each row in ListView, by telling it that Button should not be focusable.

you need to set on item click like this listView.setOnItemClickListener();

It is better to do the onlcick on listview item only.You can set some flag and toggle between the functionalities.

Related

ListView Touch is disabled with button

**I am using custom listview when i placing the button in custome view it is disabling the item touch or itemlongpress listener ...
How to use button click and listview touch simultaneously
The Problem here is , Listview having button as a child, Button will take the priority of onClick. Do the following thing
Set the property of Button to setFocusable(false);It will enable the OnClick on ListView.
For Click on Button - use onTouch instead of onClick. Which will allow you to click on button as well
try to add
android:descendantFocusability="blocksDescendants"
in the ListView tag where you define it in xml.

onItemClick is not working if there is Button in the item view

This is an item of my ListView:
The star is a Button. I set a OnClickListener for it in getView() method of the Adapter. But I now face a problem - onItemClick doesn't fire after adding the Button. I want a Button to listen for its clicks and the rest part of a view to respond with firing onItemClick. Is there a solution?
I am not sure but Button is not working in list item , so plz use ImageView instead of Button.
You can also set onClick on ImageView same as Button in your getView() method
ImageView.setOnClickListener().....etc
To make the button not focusable (but still clickable):
android:focusable="false"
android:focusableInTouchMode="false"
If you put onClickListener() on an item in getView() of Adapter , then onItemClickListener() in that Activity doesn't work. For this you can put onClickListener() on your star button and put all other Items in a Layout and put onClickListener() in getView() to that layout.

ListView onitemclick is not working

I have a ListView containing a checkbox, an imageview, two textviews and a button. The problem is after adding the checkbox and the button the onitemclick event of the ListView is not responding. Will anybody suggest a work around for the problem?
You can set both android:focusable and android:focusableInTouchMode attributes of checkbox to false and onItemClick of the list will be called. But you'll have to call CheckBox#toggle() yourself in onItemClick.
Add an onlick listner to the view. or the checkbox and handle it manually.
When you use checkbox in your listview then it consumes your click action and your check action will be performed.
You can put click listener over textview, imageview or button. you also need to handle checkbox.

Android List adapter with a button

I need to implement a list with a custom list adapter view that contains a button.
Once I add the button the onClick is not triggered.
Is there a way to make this work?
The solution is to set the button's android:focusable="false"

handle listview with button

i have a listview and button on the list how can i use both button.setonclicklistener and onListItemClick in listview
I had the same issue.But while adding button's onClick event to adapter,it was not able to listen to the list item's click event.so I used image instead of a button and then registered its click event in adapter,and that was working nicely.
Set the button.setOnCLickListener in your getView() method of the adapter.

Categories

Resources