I am running the software but when i scroll with the listview, its showing ok, but after a while i get this error message:
I am trying to display a cursor to a listview.
My Adapter class:
private class DBAdapter extends SimpleCursorAdapter {
private LayoutInflater mInflater;
private Cursor c;
private Context context;
My Constructor
public DBAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
super(context, layout, c, from, to);
this.c = c;
this.context = context;
mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
getView Method
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.match_item, null);
holder.tvHome = (TextView)convertView.findViewById(R.id.ll_home);
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
holder.tvHome.setText(c.getString(3)+"("+c.getString(6)+")");
c.moveToNext();
return convertView;
}
}
Simple View Holder
public static class ViewHolder {
public TextView tvHome;
}
}
Adapter init
Cursor cur = dh.getAll();
startManagingCursor(cur);
String[] from = new String[] { "home" };
int[] to = new int[] { R.id.ll_home};
// Now create an array adapter and set it to display using our row
DBAdapter matches = new DBAdapter(this,R.layout.match_item, cur, from, to);
setListAdapter(matches);
Can anyone help me to solve this problem?I’ve searched everywhere but i could not find any solution
Best regards,
Nicos
you’re supposed to override
newViewandbindViewwhen implementing your own cursor adapter, notgetView. i found this: Trying to override getView in a SimpleCursorAdapter gives NullPointerExceptio