gpt4 book ai didi

android - 使用 SimpleCursorAdapter.ViewBinder 更改 listView 中的颜色。安卓

转载 作者:行者123 更新时间:2023-11-30 03:50:07 25 4
gpt4 key购买 nike

我试图更改 ListView 中文本的颜色,因此我创建了 ViewBinder,但我的文本仍然是白色,没有任何变化,我能用它做什么?

// map each name to a TextView
String[] from = new String[] { "event" };
int[] to = new int[] { R.id.countryTextView };
conAdapter = new SimpleCursorAdapter(Clock.this, R.layout.day_plan, null, from, to);
setListAdapter(conAdapter); // set adapter

SimpleCursorAdapter.ViewBinder binder = new SimpleCursorAdapter.ViewBinder() {

@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex){
int getIndex = cursor.getColumnIndex("colour");
String color = cursor.getString(getIndex);
tv = (TextView)findViewById(R.id.countryTextView);

tv.setTextColor(Color.BLUE);

if(color.equals("Green"))
{
tv.setTextColor(Color.rgb(0,255,0));
return true;
}
return false;
}};

最佳答案

您是否调用了 conAdapter.setViewBinder(SimpleCursorAdapter.ViewBinder)?也就是说,您确定这些方法确实被调用了吗?

同时更改其中一行:

       tv = (TextView)view.findViewById(R.id.countryTextView); // <-- add 'view.'

关于android - 使用 SimpleCursorAdapter.ViewBinder 更改 listView 中的颜色。安卓,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14285437/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com