1
ListView에서 텍스트의 색상을 변경하려고 했으므로 ViewBinder를 만들었지 만 텍스트는 여전히 흰색이고 아무것도 변경하지 않고 무엇을 할 수 있습니까?SimpleCursorAdapter.ViewBinder를 사용하여 listView에서 색상을 변경합니다. android
// 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;
}};
어떻게 내가 전화를해야합니까? – apony
코드 바로 뒤에'conAdapter.setViewBinder (binder);'를 추가하십시오. 'Log.d()'를 넣어'setTextColor()'가 실제로 호출되는지 확인하십시오. –
메신저 오류가 발생했습니다 : 01-11 21 : 15 : 07.632 : E/AndroidRuntime (1144) : 치명적인 예외 : 주 01-11 21 : 15 : 07.632 : E/AndroidRuntime (1144) : java.lang.IllegalStateException : CursorWindow에서 행 0, col -1을 읽을 수 없습니다. 커서가 데이터에 액세스하기 전에 커서가 올바르게 초기화되었는지 확인하십시오. – apony