2013-01-11 2 views
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;   
     }}; 

답변

1

conAdapter.setViewBinder(SimpleCursorAdapter.ViewBinder)으로 전화하셨습니까? 즉, 해당 메소드가 실제로 호출되는지 확신 할 수 있습니까?

또한 그 라인 중 하나를 변경 :

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

어떻게 내가 전화를해야합니까? – apony

+1

코드 바로 뒤에'conAdapter.setViewBinder (binder);'를 추가하십시오. 'Log.d()'를 넣어'setTextColor()'가 실제로 호출되는지 확인하십시오. –

+0

메신저 오류가 발생했습니다 : 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