Question

I'm developing simple shopping list application for android. As I'm able to strikethrough & unstrike the items in the list view. But after opening back the closed application I'm unable to get updated(saved) strikethroughs for the items, all the items are cleared from strikethrough's

here is the part of the code I implemented for the 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;
                      }

here is the code populated for the 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;
             }

Kindly suggest solution for my problem where things are going wrong...Thank u.

Was it helpful?

Solution

yes i got the solution after making small edits to the getView block: here it is,

 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);
             }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top