sca*_*and 0 android scroll colors textview
我有一个listview,它是通过自定义cursoradapter生成的
一切正常,除非我在列表中上下滚动,一些textview随机变为绿色.
继承我生成列表视图的代码:
private class AchievementAdapter extends CursorAdapter {
public AchievementAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View v, Context context, Cursor cursor) {
TextView tv = (TextView) v.findViewById(R.id.achView1);
if(cursor.getString(cursor.getColumnIndex("completed")).equals("yes")) {
tv.setText(cursor.getString(cursor.getColumnIndex("name"))+" (completed)");
tv.setTextColor(Color.GREEN);
}
else {
tv.setText(cursor.getString(cursor.getColumnIndex("name")));
}
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.achievements_item, parent, false);
return v;
}
}
Run Code Online (Sandbox Code Playgroud)
我读了一些关于setcachecolorhint的内容,但该方法不适用于textview.我如何解决这个问题,以便在我滚动时随意停止更改textview颜色?
您应该在else语句中将textView颜色设置为normal,如:
@Override
public void bindView(View v, Context context, Cursor cursor) {
TextView tv = (TextView) v.findViewById(R.id.achView1);
if(cursor.getString(cursor.getColumnIndex("completed")).equals("yes")) {
tv.setText(cursor.getString(cursor.getColumnIndex("name"))+" (completed)");
tv.setTextColor(Color.GREEN);
}
else {
tv.setText(cursor.getString(cursor.getColumnIndex("name")));
tv.setTextColor(Color.BLACK); // Set your textview color as you need
}
}
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
| 归档时间: |
|
| 查看次数: |
1414 次 |
| 最近记录: |