So I have a custom ListView
that contains a CheckBox
as well as a TextView
when I click the CheckBox
I want it to cross out the TextView
my code works for the top item on the list but if I click a CheckBox
towards the bottom of the list it still crosses out the top TextView
I am using an onClick approach in the xml I know its not the norm for a ListView
its just that I didnt know how to handle two different xml elements with a onListItemClick
public void verify(View view)
{
CheckBox cb = (CheckBox) findViewById(R.id.checkBox1);
TextView t= (TextView) findViewById(R.id.label);
Toast.makeText(this, t.getText(), Toast.LENGTH_SHORT).show();
t.setPaintFlags(t.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
}
<?xml version="1.0" encoding="utf-8"?>
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="verify"
/>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tasks"
android:textSize="30px" >
</TextView>
public class MobileArrayAdapter extends ArrayAdapter<String> {
private final Context context;
private final String[] values;
public MobileArrayAdapter(Context context, String[] values ) {
super(context, R.layout.activity_task_list, values);
this.context = context;
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.activity_task_list, parent, false);
TextView textView = (TextView) rowView.findViewById(R.id.label);
textView.setText(values[position]);
return rowView;
}
}