2013-12-15 43 views
-1

如何将背景颜色添加到整行,而不仅仅是在R.id.data列上?viewbinder row backgroundcolor

adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() { 
     public boolean setViewValue(View view, Cursor cursor, int columnIndex) { 
     if (view.getId() == R.id.data) 
      { 
      if(cursor.getPosition() % 2 == 0) 
      { 
       view.setBackgroundColor(Color.LTGRAY); 
      } 
      else { 
       view.setBackgroundColor(Color.CYAN); 
      } 

      return false; 
     } 
     return false;} 
    }); 
+0

获取父视图并设置其背景 – pskink

回答

0

使用此代码我正确地设置整行的背景色!

{ 
((View) view.getParent().getParent()).setBackgroundColor(Color.parseColor("RED")); 
} 

但如何将文本颜色设置为整行?

((TextView) view.getParent().getParent()).setTextColor(Color.RED); 

不起作用!