Tofeeq Ahmad
Tofeeq Ahmad

Reputation: 11975

Clicking List-view row and child Button as well

My ListView's row has one Button. Now i want to set click event to both row and button. But as i know ListView loose its onItemClick property if we set it's child click event. So please guide me a way to doing both at once

Upvotes: 0

Views: 515

Answers (3)

codinguser
codinguser

Reputation: 5572

If you are using Buttons inside each list item, then set the click listener for the buttons on not on the list item.

Button.setOnClickListener(View.OnClickListener)

The list item clicks should go ignored and the buttons click listeners should do what you want.

Upvotes: 2

dranfi
dranfi

Reputation: 241

I don't understand why you don't want to use ListView.setOnItemClickListener(OnItemClickListener) ? Because it react instantly to a touch event. Isn't what you want?

Upvotes: 0

bigstones
bigstones

Reputation: 15267

You have to use ListView.setOnItemClickListener(OnItemClickListener). See the tutorial.

In OnItemClickListener.onItemClick() you're provided with the position of the item.

Upvotes: 1

Related Questions