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.
privatestaticclassViewHolder {
HistoryRowView rowvw;
}
classReportHistoryAdapterextendsCursorAdapter {
ViewHolder _holder;
privatestaticfinalStringINFLATER_SVC= Context.LAYOUT_INFLATER_SERVICE;
private LayoutInflater _inflater;
publicPostureReportAdapter( Context context, Cursor cursor ) {
super( context, cursor );
_inflater = (LayoutInflater) context.getSystemService(INFLATER_SVC);
}
@Overridepublic View newView(Context context, Cursor cursor, ViewGroup parent) {
Viewvw= _inflater.inflate( R.layout.reports_history_view, null );
_holder = newViewHolder();
_holder.rowvw = (HistoryRowView)vw.findViewById( R.id.rhv_history_row_vw );
vw.setTag( _holder );
return vw;
}
@OverridepublicvoidbindView(View vw, Context context, Cursor cursor) {
_holder = (ViewHolder)vw.getTag();
intpoor= cursor.getInt( 0 );
intfair= cursor.getInt( 1 );
intgood= cursor.getInt( 2 );
intdate= cursor.getInt( 3 );
_holder.rowvw.setData( poor, fair, good, date );
}
}
Post a Comment for "Problems With Listview Adapter"