0

如何在意图中获取微调器选择的位置并将其作为参数传递给另一个 Activity?

 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)并在以下方法中为其赋值,然后在意图中使用此变量

公共无效 onItemSelected(AdapterView 月,查看 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 回答