スピナーからアクティビティを開始する際に問題が発生しています。スピナーアクティビティの値を変更すると開始されますが、戻るボタンを押すと、別のスピナー値を選択するために戻ることができません。それは私の選択を保存し、ループのように何度もアクティビティを開始します。
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);
}
}