0

インテントでスピナーが選択した位置を取得し、それをパラメーターとして別のアクティビティに渡すにはどうすればよいですか?

 spinner  sp;
if (position==1) {
 do this
} if (position==2) {
 do this
}

Intent i = new Intent(this.getApplicationContext(), AgAppMenu.class);
Bundle bundle = new Bundle();
bundle.putString("mno", mobile.getText().toString());
bundle.putString("pinno", pin.getText().toString());
bundle.putLong("CODE",sp.getSelectedItemPosition());
4

4 に答える 4

1

おそらくこれがあなたのやりたいことですか?

sp.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> av, View v,
                    int pos, long id) {
                //do something with the pos var
            }
            @Override
            public void onNothingSelected(AdapterView<?> arg0) {}                       
        });
于 2012-09-05T12:36:09.477 に答える
0

私が正しく理解していれば。今あなたが欠けているのは

intent.putExtras(bundle);
startActivity(intent);

編集:

値を取得するには、次を使用します

(YourType) sp.getSelectedItem();

取得YourTypeしたい値の型です。の場合はLong、にキャストしLongます。

于 2012-09-05T12:31:07.967 に答える
0

クラス変数 (ここでは String selectedMonth) を定義し、次のメソッドで値を割り当ててから、この変数を意図的に使用します。

public void onItemSelected(AdapterView month, View arg1,int arg2, long arg3) {

    selectedMonth=  month.getItemAtPosition(arg2).toString();

        }
于 2012-09-05T12:33:40.613 に答える
0
String item;
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,int arg2, long arg3) {
item = (String) arg0.getItemAtPosition(arg2);
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});

Intent i = new Intent(this.getApplicationContext(), AgAppMenu.class);
Bundle bundle = new Bundle(); bundle.putString("CODE",item);
于 2012-09-05T12:42:36.087 に答える