Android的改变列表视图项的文字颜色 [英] Android change listview item text color
本文介绍了Android的改变列表视图项的文字颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图改变的基础上的标志的列表视图中的某些项目文本颜色(或backgroung颜色)。经过长时间的搜寻后,我也没搞清楚如何做到这一点,我打电话后,具体的行动以下循环来改变颜色:
的ListView _listView =(ListView控件)findViewById(R.id.listView2); 的for(int i = 0; I< = _ listView.getCount();我++)
{
如果(Falg ==真)
{
//这里我想改变列表视图项颜色或颜色研究背景
}
}
解决方案
您可以覆盖阵列适配器的getView方法,并改变颜色:
ArrayAdapter<串GT;适配器=
新ArrayAdapter<串GT;(getApplicationContext()
android.R.layout.simple_list_item_1,
myList中){ @覆盖
公共查看getView(INT位置,查看convertView,父母的ViewGroup){ 查看查看= super.getView(位置,convertView,父母);
TextView的文本=(TextView的)view.findViewById(android.R.id.text1); 如果(标志==真){
text.setTextColor(Color.BLACK);
} 返回视图。
}
};
i'm trying to change some items text color (or backgroung color) in a list view based on a flag . after a long search i didn't find out how to do it , i'm calling the below loop after specific action to change the color:
ListView _listView = (ListView) findViewById(R.id.listView2);
for (int i=0;i<=_listView.getCount();i++)
{
if(Falg == True)
{
//here i want to change the list view item color or backgroud color
}
}
解决方案
You can override the getView method of Array adapter and change the color:
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1,
myList) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView text = (TextView) view.findViewById(android.R.id.text1);
if (flag == True) {
text.setTextColor(Color.BLACK);
}
return view;
}
};
这篇关于Android的改变列表视图项的文字颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文