-1
我想保存微調值並檢索所選項目的值 問題是我有一個微調整數和兩個微調長 ,我不知道如何獲得值長期受 我要讓這種方法能夠設置在同一方法整型和長和iwant保存這些VAL到SP,並獲得使用這種方法,保存並獲取微調項目選擇
private void spinnerVal(int spinnerID, int move, int selection){
Spinner sp = (Spinner) findViewById(spinnerID);
ArrayList<Integer> spinnerOption = new ArrayList<>();
for (int i = 0; i < 50; i+=move) {
spinnerOption.add(i);
}
ArrayAdapter<Integer> integerArrayAdapter = new ArrayAdapter<>(this, R.layout.spinner_item, spinnerOption);
integerArrayAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
sp.setAdapter(integerArrayAdapter);
sp.setSelection(selection);
sp.setOnItemSelectedListener(this);
}
這是我對項目選擇的方法
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Editor editor;
switch (parent.getId()) {
case R.id.spinner1 /*2131492981*/:
myServer.counter1 = Integer.valueOf(parent.getItemAtPosition(position).toString());
editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putInt("counter1", myServer.counter1);
editor.apply();
return;
case R.id.spinner2 /*2131492983*/:
myServer.counter2 = (long) (Integer.valueOf(parent.getItemAtPosition(position).toString()) * 1000);
editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putLong("counter2", myServer.counter2);
editor.apply();
return;
case R.id.spinner3 /*2131492985*/:
myServer.counter3 = (long) (Integer.valueOf(parent.getItemAtPosition(position).toString()) * 1000);
editor = PreferenceManager.getDefaultSharedPreferences(this).edit();
editor.putLong("counter3", myServer.counter3);
editor.apply();
return;
default:
return;
}
}
是的,但我把它投到(長) –
,我把它轉換成長* 1000 –