I am trying to strikethrough a textview
of a listview
. I created a string of fruits and another string having values as 1 or 0, if value is1, I want to strikeout that fruit. So as per below code, Apple should be striked out.
Below is my code, I can see system executed line-row.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
, But still Apple entry is not seen as strikes out.
Please help.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String[] values = new String[]{"Apple", "Banana", "Orange", "Mango"};
String[] brk = new String[]{"1", "0", "0", "0"};
final ListView lv = (ListView) findViewById(R.id.shopList);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
System.out.println("value of child count is-" + adapter.getCount());
for (int t = 0; t < adapter.getCount(); t++) {
System.out.println("@@@@@@@@@@@@@@@@@Inside loop");
String itemValue = (String) adapter.getItem(t);
TextView row = (TextView) adapter.getView(t, null, null);
System.out.println("item value -" + itemValue);
System.out.println("corresponding brk -" + brk[t]);
if (brk[t].equals("1")) {
row.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
System.out.println("striked -" + brk[t]);
adapter.notifyDataSetChanged();
}
}
lv.setAdapter(adapter);
}
Layoutfile-
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="dhritiapps.dummylv.MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/shopList"></ListView>
</RelativeLayout>