From an answer to a past question of fine, I am getting this far. I am trying to have the selected item in my spinner that is populated from my SQLite database as a String that is used as a variable for my other queries.
//POWERSPORTS TYPE Cursor
vType = (Cursor) DataBaseHelper.getPowersportsType();
this.startManagingCursor(vType);
SimpleCursorAdapter scaType = new SimpleCursorAdapter(this,
android.R.layout.simple_spinner_item,
vType,
new String [] {DataBaseHelper.POWERSPORTS_TYPE},
new int[] {android.R.id.text1});
scaType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
vTypeSpinner = (Spinner) findViewById(R.id.typeSpinner);
vTypeSpinner.setAdapter(scaType);
vTypeSpinner.setOnItemSelectedListener(new OnItemSelectedListener(){
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String typeSelection = vTypeSpinner.getSelectedItem().toString();
}
});
//POWERSPORTS MAKE Cursor
vMake = (Cursor) DataBaseHelper.getPowersportsMake(typeSelection);
this.startManagingCursor(vMake);
SimpleCursorAdapter scaMake = new SimpleCursorAdapter(this,
android.R.layout.simple_spinner_item,
vMake,
new String [] {DataBaseHelper.POWERSPORTS_MAKE},
new int[]{android.R.id.text1});
scaMake.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
vMakeSpinner = (Spinner) findViewById(R.id.makeSpinner);
vMakeSpinner.setAdapter(scaMake);
Also, here is my query of the second spinner.
public static Cursor getPowersportsMake(String typeSelection){
return myDataBase.query(POWERSPORTS_TABLE,
new String [] {POWERSPORTS_ID, POWERSPORTS_MAKE},
POWERSPORTS_TYPE+"='"+typeSelection+"'",
null,
null,
null,
null);
}
I know I am doing something wrong because I am getting typeSelection "cannot be resolved to a variable" within my
vMake = (Cursor) DatabaseHelper.getpowersportsMake(typeSelection);
How do I use the String that is created from my onItemSelected?
Declare typeSelection
as global variable. At present it is within setOnItemSelectedListener
and hence is not visible.