I have a custom ListView
which contains a Button
. The function of this button is Delete button. Whenever user click to this button, the current Row will be deleted.
onClickListener
for this button? Thanks in advance.
In your Custom Adapater class's getView()
buttonDelete.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// Use position parameter of your getView() in this method it will current position of Clicked row button
// code for current Row deleted...
}
});
First, that will be very easy for you to handle the click on this item.
You just have to add a listener with: myButton.setOnClickListener(mBuyButtonClickListener)
. This action is usually done on the getView(...)
implementation of your ListView
.
Your listener can know what is the item position of the button by using myListView.getPositionForView(myButton)
.
Look at this sample of the listener :
private OnClickListener mBuyButtonClickListener = new OnClickListener() {
@Override
public void onClick(View v) {
final int position = getListView().getPositionForView(v);
if (position != ListView.INVALID_POSITION) {
//DO THE STUFF YOU WANT TO DO WITH THE position
}
}
};
When this is done, you should have problems to handle the click on the item itself and some other touch event propagation.
So, you should read this article that fully describes the use of multiple touchable areas inside a ListView
. It will be very helpful.
Use this inside the getView method of your adapter class.
holder.button.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With