我遇到了从微调器启动活动的问题。当我更改微调器活动的值时,但是当我按下后退按钮时,我无法返回选择另一个微调器值。它存储我的选择并一次又一次地启动活动,比如循环。
spiner1=(Spinner) findViewById(R.id.spiner1);
spiner1.setOnItemSelectedListener(new OnItemSelectedListenerWrapper(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
String str=spiner1.getSelectedItem().toString();
// Toast.makeText(getApplicationContext(), str, Toast.LENGTH_SHORT).show();
if(str.equals("Pravougaonik")) {
Intent i=new Intent(Pocetna.this, Pravougaonik.class);
startActivity(i);
}
if(str.equals("Trougao")) {
Intent i=new Intent(Pocetna.this, Trougao.class);
startActivity(i);
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
和班级:
public class OnItemSelectedListenerWrapper implements OnItemSelectedListener {
private int lastPosition;
private OnItemSelectedListener listener;
public OnItemSelectedListenerWrapper(OnItemSelectedListener aListener) {
lastPosition = 0;
listener = aListener;
}
@Override
public void onItemSelected(AdapterView<?> aParentView, View aView, int aPosition, long anId) {
if (lastPosition == aPosition) {
Log.d(getClass().getName(), "Ignoring onItemSelected for same position: " + aPosition);
} else {
Log.d(getClass().getName(), "Passing on onItemSelected for different position: " + aPosition);
listener.onItemSelected(aParentView, aView, aPosition, anId);
}
lastPosition = aPosition;
}
@Override
public void onNothingSelected(AdapterView<?> aParentView) {
listener.onNothingSelected(aParentView);
}
}