1
我有从我的CarProfile表中选择记录的光标,并使用自定义适配器在微调器选择中显示 品牌,型号和线型。我的问题是我想要选择第一个项目的“全部”,所以如果选择我可以显示所有车辆的信息。我的代码是:使用自定义光标适配器和“空”选择的微调器
// spinner 1
mDbAdapter.open();
Cursor cursorCP = mDbAdapter.fetchAllProfiles();
startManagingCursor(cursorCP);
mDbAdapter.close();
MyCustomAdapter ad = new MyCustomAdapter(this, cursorCP);
spinCP.setAdapter(ad);
public class MyCustomAdapter extends CursorAdapter {
public MyCustomAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView nameTextView = (TextView) view
.findViewById(android.R.id.text1);
String brand = cursor.getString(cursor
.getColumnIndex(DefaxedDbAdapter.KEY_BRAND));
String model = cursor.getString(cursor
.getColumnIndex(DefaxedDbAdapter.KEY_MODEL));
String licence = cursor.getString(cursor
.getColumnIndex(DefaxedDbAdapter.KEY_LICENCEPLATE));
nameTextView.setText(brand + "-" + model + "-" + licence);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View view = View.inflate(context,
android.R.layout.simple_spinner_dropdown_item, null);
return view;
}
}