简体   繁体   中英

I keep getting an error incompatible type , Required android.widget.spinner, found int

i want the method to store the result of the onItemSelected from an array of strings to an int and store it in the database

public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {     

String selection = (String)parent.getItemAtPosition(position);

if (!TextUtils.isEmpty(selection)){
    if (selection.equals("Critical")){
        mySpinner = storeEntry.PRIORITY_CRITICAL;
    }else if (selection.equals("Important")){
        mySpinner = storeEntry.PRIORITY_IMPORTANT;
    }else if (selection.equals("Casual")){
        mySpinner = storeEntry.PRIORITY_CASUAL;
    }else {
        mySpinner = storeEntry.PRIORITY_NORMAL;
    }
 }
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
    mySpinner = storeEntry.PRIORITY_NORMAL;

}

i want to get over that error

You are just confusing the name of View with variable.

mySpinner is your View. You probably made another variable to store id of currently selected item. Use that integer instead of mySpinner .

It would look something like this:

int mySpinnerSelection = storeEntry.PRIORITY_NORMAL; //Assuming priority is integer

public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {     

String selection = (String)parent.getItemAtPosition(position);

if (!TextUtils.isEmpty(selection)){
    if (selection.equals("Critical")){
        mySpinnerSelection = storeEntry.PRIORITY_CRITICAL;
    }else if (selection.equals("Important")){
        mySpinnerSelection = storeEntry.PRIORITY_IMPORTANT;
    }else if (selection.equals("Casual")){
        mySpinnerSelection = storeEntry.PRIORITY_CASUAL;
    }else {
        mySpinnerSelection = storeEntry.PRIORITY_NORMAL;
    }
 }
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
    mySpinnerSelection = storeEntry.PRIORITY_NORMAL;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM