我想在文本中設置strikethough當用戶單擊listView內的複選框。假設我有三個項目內的listView,但是當我點擊第一項中的複選框,它只在文本strikethough最後一項。在列表視圖中設置Strikethough文本android
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listView = (ListView) findViewById(R.id.productList);
model = helper.getAllProduct(list);
startManagingCursor(model);
listView.setAdapter(new ShoppingListAdapter(this,model));
class ShoppingListAdapter extends ResourceCursorAdapter {
public ShoppingListAdapter(Context context ,Cursor c) {
super(context,R.layout.productrow,c);
// TODO Auto-generated constructor stub
}
@Override
public void bindView(View row, Context context, Cursor c) {
// TODO Auto-generated method stub
listName = (TextView) row.findViewById(R.id.produtName);
final CheckBox listCheck=(CheckBox)row.findViewById(R.id.check);
listCheck.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton view, boolean isChecked) {
// TODO Auto-generated method stub
if(listCheck.isChecked()){
listName.setPaintFlags(listName.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
//listName.setTextColor(_context.getResources().getColor(R.color.red));
// listName.setText("go");
}
}
});
有人知道wat是我的錯嗎?
也在onCheckedChange之外設置標誌,對於已經檢查過的標誌。 – Doomsknight
設置標誌外?意思是我也在外面設置了PaintFlag?對不起,我是新的Android編程.. – johnk