我有這樣的微調:共享偏好與微調不維護國家
// Spinner 1
final Spinner plan = (Spinner) dialog.findViewById(R.id.spinner1);
strings = getResources().getStringArray(R.array.paymentplan);
sAdapter = new SpinnerAdapter(this,
android.R.layout.simple_spinner_item, strings);
sAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
plan.setAdapter(sAdapter);
// plan.setAdapter(spinner1Adapter);
plan.setSelection(prefsDisplay.getInt("spinnerSelection1", 0));
plan.setOnItemSelectedListener(new MyOnItemSelectedListenerPlan());
當用戶點擊,我希望它來保存狀態:
public void onClick(View v) {
Editor editor2 = prefsPlan.edit();
int selectedPosition1 = plan.getSelectedItemPosition();
editor2.putInt("spinnerSelection1", selectedPosition1);
editor2.commit();
}
它保存在SharedPref的位置,但微調器回到默認狀態。有人在這裏看到什麼?
謝謝你,我會檢查出來 – KickingLettuce