I have seen many examples but none is according to my problem...in my case i have a custom listview with custom adapter the checkboxex are primarily hidden and when option menu button is clicked the checkboxes get visible and the focusability is also set to true and listview no more receive list item click listener...i also have code to save the states of the checkboxes in SparseBooleanArray but the biggest problem is that in the getView() as it doesnt call on checkbox check so the check state is wrongly saved for example if i have firstly 5 items in my list view...the position from the public View getView(int position,View convertView,ViewGroup parent) will be 6 beacuse the last item will be at position 6.so in my code
@Override
public View getView(final int position,View convertView,ViewGroup parent)
{
//currentPosition=position;
Log.v("Position",""+position);
Log.v("ConvertView", ""+convertView);
View row=convertView;
if(row==null)
{
LayoutInflater inflater=((Activity)context).getLayoutInflater();
row=inflater.inflate(layoutResourceId, parent,false);
holder=new Feedbacks();
holder.lvGuestName=(TextView)row.findViewById(R.id.guestName);
holder.checkBox=(CheckBox)row.findViewById(R.id.clearCheck);
holder.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if(isChecked)
{
checks.put(position, true);
System.out.println("checking at pos:"+position);
}
else
{
checks.put(position, false);
System.out.println("unchecking at pos:"+position);
}
}
});
row.setTag(holder);
}
else
{
holder=(Feedbacks)row.getTag();
}
if(showCheckbox)
{
holder.checkBox.setVisibility(View.VISIBLE);
}
else
{
holder.checkBox.setVisibility(View.GONE);
}
holder.lvGuestName.setText(feedbackList.get(position).getGuestName());
holder.checkBox.setChecked((checks.get(position)));
System.out.println("seting check at pos:"+position);
return row;
}
}
now when on if(isChecked)
{
now even if i click on the 0 position item it will get the position to be 6
i know it because when checkbox is checked/unchecked the getView() will not called and hence
checks.put(position, true);
System.out.println("checking at pos:"+position);
}checks.put(position,true);
will not get the respective position...
i know i can easily do it with on listitem click with checkbox focusability false but im curious to learn new things thats why just want to know if any one know the according to my way how can i get the position of the respective checkbox checked in the listview...Any kind of help will be most appreciated and valuable for me...
Thanks in advance