I want to add onClick
event for buttons used in item of Listview
.
How can I give onClick
event for buttons in List Item.
public View getView(final int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = getLayoutInflater();
View row = inflater.inflate(R.layout.vehicals_details_row, parent, false);
Button deleteImageView = (Button) row.findViewById(R.id.DeleteImageView);
deleteImageView.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//...
}
});
}
But you can get an issue - listView row not clickable. Solution:
android:focusable="true"
android:focusable="false"
You can set the onClick
event in your custom adapter's getView
method..
check the link http://androidforbeginners.blogspot.it/2010/03/clicking-buttons-in-listview-row.html
Try This,
public View getView(final int position, View convertView,ViewGroup parent)
{
if(convertView == null)
{
LayoutInflater inflater = getLayoutInflater();
convertView = (LinearLayout)inflater.inflate(R.layout.YOUR_LAYOUT, null);
}
Button Button1= (Button) convertView .findViewById(R.id.BUTTON1_ID);
Button1.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// Your code that you want to execute on this button click
}
});
return convertView ;
}
It may help you....
In your custom adapter inside getView method :
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Do things Here
}
});
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