日期:2014-05-16 浏览次数:20457 次
private class MyCursorAdpter extends CursorAdapter { private int columnIndex; public MyCursorAdpter(Context context, Cursor c, int col) { super(context, c); this.columnIndex = col; } @Override public View newView(Context context, Cursor cursor, ViewGroup parent) { final LayoutInflater inflater = LayoutInflater.from(context); final TextView view = (TextView) inflater.inflate( android.R.layout.simple_dropdown_item_1line, parent, false); view.setText(cursor.getString(columnIndex)); return view; } @Override public void bindView(View view, Context context, Cursor cursor) { ((TextView) view).setText(cursor.getString(columnIndex)); } @Override public String convertToString(Cursor cursor) { return cursor.getString(columnIndex); } @Override public Cursor runQueryOnBackgroundThread(CharSequence constraint) { if (constraint != null) { String selection = "name like \'" + constraint.toString() +"%\'"; return sqlite.query("test", columns, selection, null, null, null, null); } else { return null; } } }
private void createDatas() { String createTable = "create table test (name varchar(255), _id varchar(255))"; sqlite.execSQL(createTable); ContentValues values = new ContentValues(); values.put("name", "nicole"); values.put("_id", "0"); sqlite.insert("test", null, values); values.put("name", "nicolas"); values.put("_id", "1"); sqlite.insert("test", null, values); values.put("name", "jean"); values.put("_id", "2"); sqlite.insert("test", null, values); values.put("name", "jennyfer"); values.put("_id", "3"); sqlite.insert("test", null, values); }