[英]I'm trying to swap two values , while running the code im getting this error " Incompatible types. Found: 'int', required: 'int[]' "
[英]I keep getting an error incompatible type , Required android.widget.spinner, found int
我想要將 onItemSelected 的結果從字符串數組存儲到 int 並將其存儲在數據庫中的方法
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;
}
我想克服那個錯誤
您只是將 View 的名稱與變量混淆了。
mySpinner是您的視圖。 您可能創建了另一個變量來存儲當前所選項目的 id。 使用該整數而不是mySpinner
。
它看起來像這樣:
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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.