I have a ListView that’s populated from a SimpleCursorAdapter each row containing 3 different TextViews. I only want to modify one of the TextViews for all rows with a ViewBinder (R.id.text65), however it keeps updating all 3 TextViews of every row. Here’s my code:
cursorAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
sign = (TextView) view;
SharedPreferences currency = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String currency1 = currency.getString("Currency", "$");
sign.setText(currency1);
return true;
}
});
P.S. I tried (TextView) findViewById(R.id.text65); and I got a Force close.
Solution 1:
You should check the column index in the
viewbinder:Note, the column index, is the DBcolumn index of the currency / the index of the column in whatever is your data source.
Solution 2:
You are probably defining an
int[]for the fields to bind to in yourlistviewfor example :… Conditionally, you can simply pass
0instead of the layout ids of the fields that you donT want to be bound / shown.This way only the Currency field will be bound.
Also, the reason you get the force close is because, technically, there is no single
text65in your contentView but many. You cannot access it from the main layout level. It is unique only in the scope of a single row.Update :
Solution 3:
Check the
idof the view in theViewBinderCould you try this?
Useful hint: you can use the
Log.vto check certain values in your code without having to debug it.Hope it helps.