I have problem wit changing backgroud color in my project. I'm just trying to change list background color with condition in ViewBinder. But color of backgroung didn't changing.
My ViewBinder
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
LinearLayout ll = (LinearLayout) findViewById(R.id.listViewTopLinearLayout);
String voted = cursor.getString(VOTED_COLLUMN_INDEX);
if (columnIndex == cursor.getColumnIndex(AssetsTableHelper.COLUMN_VOTED)) {
boolean is_checked = voted.equals("true");
if (is_checked) {
((View) ll.getParent()).setBackgroundResource(R.color.votedColor);
((View) view.getParent()).setBackgroundResource(R.color.votedColor);
} else {
((View) view.getParent()).setBackgroundResource(R.color.notVotedColor);
}
return true;
}
return false;
};
onCreate
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
integrator = new IntentIntegrator(this);
datasource = new AssetsDataSource(this);
Cursor cursor = datasource.getCursorForAllAssets();
adapter = new SimpleCursorAdapter(this, R.layout.listview_item_row,cursor, UI_BINDING_FROM,UI_BINDING_TO, 0);
adapter.setViewBinder(new CustomViewBinder());
setListAdapter(adapter);
List_item_row.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/tvSurname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#000000"
android:textSize="20sp"
android:textStyle="bold" />
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#000000"
android:layout_marginLeft="5dp"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="@+id/tvHomeNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />