Sunday, November 18, 2012

How to get correct position of list item when custom list button clicked


use setTag attribute of the View..............

use this button code in getView() method
Button call = (Button) rowView.findViewById(R.id.button1);
call.setTag(position);

and after that directly use onClick listner for that listview item button
call.setOnClickListener(new OnClickListener() {

      @Override
      public void onClick(View v) {
         int which = -1;
         Obejct obj =  v.getTag();
         if(obj instaceof Integer){
         which  = ((Integer)obj).intValue();
         }

      if(which >-1){
      //write code here to get value from any way using position means which
      Toast.makeText(getContext(), "Current clicked position is : "+which, 1).show();
   }
 }
});

Reference from: http://stackoverflow.com/questions/11156078/android-get-the-listview-item-from-button-clicked-in-custom-listview

No comments:

Post a Comment