的我的下一个estructure:更改文本颜色编程ListView中谁依赖arrayadapter
ArrayList<String> arrayList = new ArrayList<>();
list = (ListView) findViewById(R.id.list1);
arrayAdapter = new ArrayAdapter<String>(INGR_NOTAS.this, R.layout.list_item_clickable, R.id.txtitem, arrayList);
list.setAdapter(arrayAdapter);
在列表视图的布局来自list_item_clickable.xml和textiview “txtitem” 里面:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/txtitem"
android:textColor="@android:color/white"
android:background="@android:drawable/editbox_dropdown_dark_frame"
android:textAlignment="center" />
</LinearLayout>
这个结构在很多类中都有工作,并且像Textview所说的那样,textcolor总是白色的,但现在我需要根据文本的值(有时是白色,有时是红色)更改listview中的textcolor。那么,我怎样才能添加这个改变,而不会在代码的其余部分增加一个很大的影响长期的所有应用程序?
感谢您的任何建议!
我试了一下,测试我是否可以更改代码中文本的颜色。我只是将Color.RED放在setTextColor中,但没有任何改变。 –
是否向arrayList添加了字符串? – Oleg
当我添加,取决于我使用的情况: –