Reputation: 21
I'm doing a Shopping List in Android, for which I'm storing Products in SQLite Database.
The Products are Clickable so that they should get strikethrough. Updating Database works fine but the strikethrough is not made on the correct item. /** * Loads the List from DB, puts Data into Listview and strikes through inactive Products */
public void loadListe()
{
//---get all titles---
meineListe.clear();
adapter.clear();
db.open();
Cursor c = db.getAllTitles();
ArrayList<String> strikedItems = new ArrayList<String>();
strikedItems.clear();
if (c.moveToFirst())
{
do {
if (c.getInt( 0 )==1) {
meineListe.add(c.getString( 1 ));
strikedItems.add( c.getString( 1 ) );
}
else meineListe.add( c.getString( 1 ));
} while (c.moveToNext());
}
db.close();
//Strike Through on inactive Items
list = this.getListView();
for (int i = 0; i < list.getChildCount(); i++) {
LinearLayout row = (LinearLayout) list.getChildAt( i );
TextView title;
title = (TextView) row.getChildAt( 0 );
//System.out.println("zeile "+i+ " "+title.getText());
if(strikedItems.contains( title.getText() ))
{
title.setPaintFlags( Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
System.out.println("zeile "+i+ " Title: "+title.getText());
title.setTextColor(0xFFFF0000); //black
}
}
Upvotes: 0
Views: 1287
Reputation: 38727
The child Views of the ListView are only those items which are visible at the time, not the whole array of items.
You don't iterate them like this, you need to set the strikeout property from your Adapter.getView()
implementation.
Upvotes: 1