Search code examples
androidlistviewtextviewstrikethrough

Listview Textview Strikethrough


Hello is it possible to have a listview containing textview be strikethrough ?

for example

if(itemText.equals("Done")){
//  strikethrough here. 
}else{
// no strikethrought here. 
}

the thing is, when I do this the item plus the first index of the listview gets strike through

enter image description here

is there a way to only strike the click item ?

please help me thank you


Solution

  • I hope I've finally understood what you want done. But here's a shot:

    You have to add an onListItemClick method like so:

      @Override
      public void onListItemClick(ListView l, View v, int position, long id) {        
          super.onListItemClick(l, v, position, id);
    
          TextView item = (TextView) v.findViewById(R.id.textView);
          item.setPaintFlags(item.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
      }
    

    Hopefully this is what you wanted as I've got it in one of my apps and it works perfectly. Let me know! Hope it does.