Pra*_*mar 1 android android-listview simplecursoradapter android-viewbinder
我已经列出了使用数据库的名称SimpleCursorAdapter,我想使用SimpleCursorAdapter.ViewBinder's方法更改特定名称的颜色.我在运行此方法时遇到问题,我的数据库包含不同的名称,但ListView会将所有namse显示为一个特定名称.我究竟做错了什么?如何更改特定名称的文本颜色?有可能用ViewBinder吗?
这是我的代码部分ViewBinder:
SimpleCursorAdapter.ViewBinder binder = new SimpleCursorAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
// TODO Auto-generated method stub
String[] temp = dh.return_result();
tv = (TextView)findViewById(R.id.textView1);
tv = (TextView) view;
for(int i = 0; i<temp.length; i++)
{
if(temp[i].equalsIgnoreCase("Ameer Zhann"))
{
tv.setText(temp[i]);
tv.setTextColor(Color.rgb(58, 58, 224));
return true;
}
}
return false;
}
};
Run Code Online (Sandbox Code Playgroud)
这是我的输出图像:

我怎么解决这个问题?
试试这种方式:
public boolean setViewValue(View view, Cursor cursor, int columnIndex){
int getIndex = cursor.getColumnIndex("Name");
String empname = cursor.getString(getIndex);
tv = (TextView) view;
tv.setTextColor(Color.WHITE);
tv.setText(empname);
if(empname.equals("Any String"))
{
tv.setTextColor(Color.rgb(58, 58, 224));
return true;
}
return false;
}
Run Code Online (Sandbox Code Playgroud)