这里我有2个微调器。单击button1时,将执行以下过程。该过程是关于获取微调器值,并且这些值必须存储在总变量中,并且必须将选定的微调器值重置为原始位置。此操作应执行单击按钮的次数。
Spinner cre1,cre2;
浮动总数;
String credit1,credit2;
ArrayAdapter spin1;
ArrayAdapter spin2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_example);
creditd = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spin1);
graded = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, spin2);
cre1 = (Spinner) findViewById(R.id.cre1);
spin1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
cre1.setAdapter(creditd);
cre1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
credit1 = adapterView.getItemAtPosition(i).toString();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
cre2 = (Spinner) findViewById(R.id.cre2);
spin2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
gra1.setAdapter(graded);
gra1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
credit2 = adapterView.getItemAtPosition(i).toString();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
total += convf(credit1) + convf(credit2);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button1:
onCreate(new Bundle());
break;
case R.id.button2:
startActivity(new Intent(this, Result.class));
break;
}
}
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
答案 0 :(得分:0)
您可以使用Spinners setSelection方法重置所选位置,如您所愿:
spin1.setSelection(position);
spin2.setSelection(position);