Would very much appreciate any help or hint on were to go next.
I\'m trying to change the content of a row in ListView programmatically. In one row there are 3 TextV
For CursorAdapter
and subclasses, you should override newView()
and bindView()
instead of getView()
.
More importantly, though, you should not get calling super.getView()
. That is where you are crashing.
Actually you should use a ViewBinder to achieve your custom binding. This way you do not have to override any code. Just make sure that you return true when you have set the value of the view otherwise the adapter will overwrite the value.
public void refresh() {
Cursor cursor = ....get cursor....
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
R.layout.list_item,
cursor,
new String[] { KEY_NAME, KEY_SHORT_DESC},
new int[] { R.id.icon, R.id.text1});
adapter.setViewBinder(new ProductViewBinder());
setAdapter(adapter);
}
private static class ProductViewBinder implements ViewBinder {
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
if (view instanceof ProgressBar) {
String result = cursor.getString(2);
Int resInt = Int.parseInt(result);
if (resInt == 0) {
((ProgressBar)view).setIndeterminate(true);
return true;
}
}
return false;
}
}
There is no need for getView()
when extending the SimpleCursorAdapter
class. All the functionality of getView()
we get from the overriden newView()
and bindView()
methods.
if (convertview == null) // is equal to `newView()` and
if (convertview != null) // is equal to `bindView()`
One main difference is in getView()
; we have the position as a parameter and in simpleCursorAdapter
we get the position as getPositionForView(view)
view is a parameter of bindView()
.
example: Mostly we are using Listview
to put values...so you call ListViewObj.getPositionForView(view)