我正在为Android开发简单的购物清单应用程序。 因为我能够删除&取消列表视图中的项目。但在打开已关闭的应用程序后,我无法更新(保存)项目的删除线,所有项目都从删除线中删除
这是我为onItemClickListener
实现的代码的一部分 if (checkedVals[position]==true)
{
TextView text1 = (TextView)arg1.findViewById(R.id.customitemsrowTV);
text1.setPaintFlags(text1.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
text1.setTextColor(0xff000000);
String strikethrough1 = "false";
dbAdapterItems.updateItemsStrikethroughRecord(rowitemsid, strikethrough1);
//checkedVals[position] = false;
}
else
{
TextView text1 = (TextView)arg1.findViewById(R.id.customitemsrowTV);
text1.setPaintFlags(text1.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
text1.setTextColor(0xff888888);
String strikethrough1 = "true";
dbAdapterItems.updateItemsStrikethroughRecord(rowitemsid, strikethrough1);
//checkedVals[position] = true;
}
这是为listview填充的代码:
TextView itemsRowTv = (TextView)convertView.findViewById(R.id.customitemsrowTV);
TextView quantityRowTv = (TextView)convertView.findViewById(R.id.customquantityrowTV);
TextView priceRowTv = (TextView)convertView.findViewById(R.id.custompricerowTV);
cItems.moveToPosition(position);
String itemName = cItems.getString(1);
checkedVals[position] = Boolean.parseBoolean(cItems.getString(3));
String itemQuantity = cItems.getString(4);
String itemPrice = cItems.getString(5);
if (checkedVals[position]==true)
{
itemsRowTv.setText(itemName);
//TextView text1 = (TextView)arg1.findViewById(R.id.customitemsrowTV);
// itemsRowTv.setPaintFlags(itemsRowTv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
// itemsRowTv.setTextColor(0xff000000);
// checkedVals[position] = false;
}
else
{
// TextView text1 = (TextView)arg1.findViewById(R.id.customitemsrowTV);
itemsRowTv.setText(itemName);
itemsRowTv.setPaintFlags(itemsRowTv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
itemsRowTv.setTextColor(0xff888888);
// checkedVals[position] = true;
}
请在出现问题的地方为我的问题提出解决方案......谢谢你。
答案 0 :(得分:1)
是的,我在对getView块进行小编辑后得到了解决方案: 在这里,
if (checkedVals[position]==true)
{
itemsRowTv.setPaintFlags(itemsRowTv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
itemsRowTv.setTextColor(0xff888888);
}
else if(checkedVals[position]==false)
{
itemsRowTv.setPaintFlags(itemsRowTv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
itemsRowTv.setTextColor(0xff000000);
}