[英]Android: Connecting to SQLite database.. Problem with Cursor
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如果有任何人有任何想法..我會提前評估.. Thanx。
與CursorAdapter文檔中一樣:
Cursor必須包含名為“_id”的列,否則此類將不起作用。
例:
SELECT id _id, name, address FROM user
例:
SELECT 1 _id, name, address FROM user
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.