0
我有一個微調設置在屏幕上,我從另一個屏幕傳遞一個字符串。我希望該字符串被設置爲微調器的默認值。我已經看過帖子,並試圖實現它,但不知何故,它不工作。微調的默認不工作
這裏是我的代碼:
//workRequestFetched is a private String object
workRequestFetched = extras.getString("workRequest");
workRequestSpinner = (Spinner) findViewById(R.id.workRequestSpinner);
//ServiceCall is a function call to the web service it works fine otherwise, please don't worry about it.
ArrayList<String> workRequests = ServiceCall.workRequests;
ArrayAdapter<String> workRequestAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item,
workRequests);
選擇的是布爾如果字符串已通過與否,檢查。我已經打印出來檢查執行線程是否進入if子句,並且確實如此,所以認爲問題不在那裏。
if(selected){
System.out.println("Entered selected- "+workRequestFetched);
//This is what supposed to set the spinner's default to the position of the string right? but it doesn't work!
int spinnerPosition = workRequestAdapter.getPosition(workRequestFetched);
workRequestSpinner.setSelection(spinnerPosition);
}
workRequestAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
workRequestSpinner.setAdapter(workRequestAdapter);
任何人都可以指出錯誤嗎?謝謝!
作品!謝謝。我需要在最後設置默認選擇。 – Harsh
是的,你知道了! –