i have cursor which selects records from my CarProfile table and use custom adapter to show
brand, model and the linenceplate in the spinner selection. my problem is that i want to have selection which says “ALL” for a first item, so if chosen i could display information for all the cars. my code is:
// 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;
}
}
ok my fix at the end was to use array adapter with the help of hashmap to store the id’s. here is the code i used
and then after selecting an item from spinner you can get the id like that