Problems With Listview Adapter
I have an app which uses a Listview to display Lectures. The Lectures are colour coded according to their type. I used a custom adapter to control the different colours of each lec
Solution 1:
The problem is that your code in getView() gets its data from the class variable mycursor
, but when you call changeCursor, the mycursor
variable is not getting updated, so you still see the original list. Rather than using mycursor
, you should call getCursor()
instead.
Solution 2:
Have you tried calling adapter.notifyDataSetChanged() after you call the changeCursor? That should force your menuList to be updated.
Solution 3:
Instead of using getView, you may want to use newView and bindView methods instead...here's an example from some code I've written.
private static class ViewHolder {
HistoryRowView rowvw;
}
class ReportHistoryAdapter extends CursorAdapter {
ViewHolder _holder;
private static final String INFLATER_SVC = Context.LAYOUT_INFLATER_SERVICE;
private LayoutInflater _inflater;
public PostureReportAdapter( Context context, Cursor cursor ) {
super( context, cursor );
_inflater = (LayoutInflater) context.getSystemService(INFLATER_SVC);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View vw = _inflater.inflate( R.layout.reports_history_view, null );
_holder = new ViewHolder();
_holder.rowvw = (HistoryRowView)vw.findViewById( R.id.rhv_history_row_vw );
vw.setTag( _holder );
return vw;
}
@Override
public void bindView(View vw, Context context, Cursor cursor) {
_holder = (ViewHolder)vw.getTag();
int poor = cursor.getInt( 0 );
int fair = cursor.getInt( 1 );
int good = cursor.getInt( 2 );
int date = cursor.getInt( 3 );
_holder.rowvw.setData( poor, fair, good, date );
}
}
Post a Comment for "Problems With Listview Adapter"