我正在尝试删除 textview
listview
。我创建了一串水果和另一个字符串,其值为1或0,如果值为1,我想要取出那个水果。因此,根据以下代码,Apple应该被删除。
下面是我的代码,我可以看到系统执行的行 - row.setPaintFlags(Paint.STRIKE_THRU_TEXT_FLAG);
,但Apple仍然没有被视为罢工。
请帮忙。
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>
答案 0 :(得分:1)
你可以通过Spanneble
字符串StrikeOut文字:
tv.setText(s, TextView.BufferType.SPANNABLE);
Spannable spannable = (Spannable) tv.getText();
spannable.setSpan(new StrikethroughSpan();, 0, s.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
答案 1 :(得分:0)
答案 2 :(得分:0)
试试这种方式
row.setPaintFlags(tv.getPaintFlags()| Paint.STRIKE_THRU_TEXT_FLAG);
OR
.setPaintFlags( Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG);
OR 您可以使用Spannablestring
http://androidcocktail.blogspot.in/2014/03/android-spannablestring-example.html