解决方案1:
您应该检查以下中的列索引viewbinder
:
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (columnIndex == cursor.getColumnIndexOrThrow(**??**)) // 0 , 1 , 2 ??
{
sign = (TextView) view;
SharedPreferences currency = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String currency1 = currency.getString("Currency", "$");
sign.setText(currency1);
return true;
}
return false;
}
请注意,列索引是货币的 DBcolumn 索引/无论是您的数据源中的列的索引。
解决方案2:
例如,您可能正在int[]
为要绑定的字段定义一个listview
:
// and an array of the fields we want to bind those fields to
int[] to = new int[] { R.id.field1, R.id.field2, R.id.Currency };
SimpleCursorAdapter entries = new SimpleCursorAdapter(this, R.layout.row, cursor, from, to);
...有条件地,您可以简单地传递0
而不是您不想绑定/显示的字段的布局ID。
int[] to = new int[] { 0, 0, R.id.Currency };
这样,只有 Currency 字段将被绑定。
此外,您获得强制关闭的原因是,从技术上讲,您的contentView中没有single 而是many。您无法从主布局级别访问它。它仅在单行范围内是唯一的。text65
更新 :
解决方案3:
检查id
视图中的ViewBinder
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
int viewId = view.getId();
Log.v("ViewBinder", "columnIndex=" + columnIndex + " viewId = " + viewId);
if(viewId == R.id.text65)
{
sign = (TextView) view;
SharedPreferences currency = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
String currency1 = currency.getString("Currency", "$");
sign.setText(currency1);
return true;
}
return false;
}
你能试试这个吗?
有用的提示:您可以使用Log.v
来检查代码中的某些值,而无需对其进行调试。
希望能帮助到你。