private class MContactsAdapter extends SimpleCursorAdapter {
private Context context;
private DataBaseHelper dbHelper;
private Cursor currentCursor;
public MContactsAdapter(Context context, int layout, Cursor c,
String[] from, int[] to, DataBaseHelper dbHelper) {
super(context, layout, null, from, to);
this.currentCursor = c;
this.context = context;
this.dbHelper = dbHelper;
}
public View getView(int pos, View inView, ViewGroup parent) {
View v = inView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.main, null);
}
this.currentCursor.moveToPosition(pos);
TextView cBox = (TextView) v.findViewById(R.id.txtDisplayName);
cBox.setText(this.currentCursor
.getString(this.currentCursor
.getColumnIndex("lat")));
TextView txtTitle = (TextView) v.findViewById(R.id.txtName);
txtTitle.setText(this.currentCursor.getString(this.currentCursor
.getColumnIndex("lng")));
TextView txtaddress = (TextView) v.findViewById(R.id.txtPhone);
txtaddress.setText(this.currentCursor.getString(this.currentCursor
.getColumnIndex("address")));
return (v);
}
}
我通过不同的方法创建了这个Adapter类。每当它通过异常调用super(context,layout,cursor,from,to)方法时。因为光标。我用sqlite数据库表填充我的光标。我不知道为什么它不接受填充光标。 如果我给null而不是游标,那么它工作正常:S 如果有人有任何想法..我会appriciate .. Thanx提前。
答案 0 :(得分:2)
与CursorAdapter文档中一样:
Cursor必须包含名为“_id”的列,否则此类将无效。
示例:
SELECT id _id, name, address FROM user
示例:
SELECT 1 _id, name, address FROM user