質問

Right now I am almost done writing my app. All I need is a bit help on getting the selected String value from a spinner populated from my database by a simple cursor adapter. I am not sure how I can get the String from my spinner and pass it to a different cursor and use the string in a query, that will populate depending on the first choice of the spinner, and so on with other spinners.

Here is the code I am using for one of my spinners.

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);

And this is my query for the next spinner in my xml layout

static String MakeWhere = "POWERSPORTS_TYPE=?";
public static Cursor getPowersportsMake(){
return myDataBase.query(POWERSPORTS_TABLE, 
    new String [] {POWERSPORTS_ID, POWERSPORTS_MAKE}, 
    MakeWhere, 
    null, 
    POWERSPORTS_MAKE, 
    null, 
    null);
}

Any comments or suggestions are welcomed.

役に立ちましたか?

解決

to get the item selected you need to set the onItemSelectedListener

then in your onItemtSelected all you would do is

String selection = vTypeSpinner.getSelectedItem().toString();
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top