Android: Listview Elements With Multiple Clickable Buttons

Android: ListView elements with multiple clickable buttons

The solution to this is actually easier than I thought. You can simply add in your custom adapter's getView() method a setOnClickListener() for the buttons you're using.

Any data associated with the button has to be added with myButton.setTag() in the getView() and can be accessed in the onClickListener via view.getTag()

I posted a detailed solution on my blog as a tutorial.

Android: ListView elements with multiple clickable elements

you need to make baseAdpter to achieve this

public class ContactsAdapter extends BaseAdapter {

ArrayList<ContactInfo> mlist;
Context mcontext;


public BluetoothChatadpter(Context context,ArrayList<ChatInfo> mchtlist) {
mlist = mchtlist;
mcontext = context;

}

@Override
public int getCount() {
return mlist.size();
}

@Override
public Object getItem(int postion) {
return mlist.get(postion);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertview, ViewGroup viewgroup){
View view = null;
if(convertview == null){
LayoutInflater inflater = context.getLayoutInflater();
view = inflater.inflate(R.layout.contactrow, null);

ContactHolder holder = new ContactHolder();

holder.txtviewfirstname = (TextView)view.findViewById(R.id.firstname);
holder.txtviewphone = (TextView)view.findViewById(R.id.phone);
holder.chkselected = (CheckBox)view.findViewById(R.id.check);

setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// to open the selected file in resp

// do your work here
}});


chkselected .setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Toast.makeText(context,// "checked is clicke="+pos, 12).show();
if (chkselected.isChecked())
{

// do your work here
} else {

// do your work here
}
}
});



view.setTag(holder);

}
else{
view = convertview;
}
ContactHolder holder2 = (ContactHolder) view.getTag();
holder2.txtviewfirstname.setText(list.get(position).firstname);
holder2.txtviewphone.setText(list.get(position).phonenumber);
holder2.chkselected.setChecked(list.get(position).selected);
return view;
}

}

Getting the exact clicked button in ListView with Multiple clickable buttons

see this link in this link you will find how to find onclick of button

http://tausiq.wordpress.com/2012/08/22/android-listview-example-with-custom-adapter/

http://android-helper.blogspot.in/search/label/ListView

Multiple clickable items in ListView inside android widget

My bad. I should be using

remoteViews.setPendingIntentTemplate(R.id.list_view,
*<PendingIntent>*);

for both the buttons, but I was trying to use the button's ID directly in the second. Got fixed.



Related Topics



Leave a reply



Submit