I have a little functionality to strike out and unstrike out a list view when a list item is clicked. My code goes Here:
public void markComplete(View v)
{
Button b1 = (Button)findViewById(R.id.Completeit);
Button b2 = (Button)findViewById(R.id.InCompleted);
try{
TextView tv = (TextView)findViewById(R.id.textViewx);
tv.setPaintFlags(tv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}catch(Exception e){e.printStackTrace();}
b1.setVisibility(-1);
b2.setVisibility(1);
}
public void markInComplete(View v)
{
Button b1 = (Button)findViewById(R.id.Completeit);
Button b2 = (Button)findViewById(R.id.InCompleted);
try{
TextView tv = (TextView)findViewById(R.id.textViewx);
tv.setPaintFlags( tv.getPaintFlags() & (~ Paint.STRIKE_THRU_TEXT_FLAG));
}catch(Exception e){e.printStackTrace();}
b1.setVisibility(1);
b2.setVisibility(-1);
}
I have two buttons for checking and unchecking the list item.It works for the first list item alone. If i try to click 2nd list item, the striking & unstriking is done only on 1st item. Any help is appreciated and Thanks in advance
Your findViewById call is going to return the first element in your view that it finds. If you have multiple, then this is going to be a problem. It will always find the first table cell. The solution here is to save your buttons, and treat each cell as a separate view.