在我向你解释之前,我告诉过你,我一直在 stackoverflow 和许多网站中搜索所有问题,所以不要将其标记为重复或任何负面行为。我已经尝试过,努力工作,但仍然卡在这里很多天。我需要你解决一个简单的问题。
我有一个关于微调器的问题。我尝试使用共享首选项来保存默认值,它起作用了。但是当我每次都尝试保存选定的微调器值时,它失败了,每当我返回上一页时,我都无法检索我之前选择的值。
FontSettings.java
public class FontSettings extends AppCompatActivity {
private Spinner spinner1, spinnerLatin;
private SharedPreferences mMyPrefs;
private SharedPreferences.Editor mMyEdit;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_font);
// toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//this line shows back button
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//Display data size teks arab in dropdown list spinner
Spinner spinnerBackgroundChange = (Spinner)findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> spinnerArrayAdapter = ArrayAdapter.createFromResource(this, R.array.country_arrays, android.R.layout.simple_spinner_item);
spinnerArrayAdapter.setDropDownViewResource(R.layout.textview_with_background);
spinnerBackgroundChange.setAdapter(spinnerArrayAdapter);
//save selected spinner value
SharedPreferences sharedPref = getSharedPreferences("My_Prefs", Context.MODE_PRIVATE);
SharedPreferences.Editor editor=sharedPref.edit();
editor.putInt("spinnerValue", spinnerBackgroundChange.getSelectedItemPosition());
editor.apply();
//Display data size teks latin in dropdown list spinner
Spinner spinnerLatin = (Spinner)findViewById(R.id.spinnerLatin);
ArrayAdapter<CharSequence> spinnerArrayLatin = ArrayAdapter.createFromResource(this, R.array.country_arrays, android.R.layout.simple_spinner_item);
spinnerArrayLatin.setDropDownViewResource(R.layout.textview_with_background);
spinnerLatin.setAdapter(spinnerArrayLatin);
// spinnerLatin default value
spinnerLatin.setSelection(1);
addListenerOnSpinnerItemSelection();
addListenerOnSpinner2ItemSelection();
}
慕尼黑5688855
相关分类