如何在意图中获得选定的微调器值?

时间:2012-09-05 12:28:02

标签: android

如何在意图中获得微调器的选定位置并将其作为参数传递给另一个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 个答案:

答案 0 :(得分: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) {}                       
        });

答案 1 :(得分:0)

如果我理解正确的话。现在你所缺少的是

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

编辑:

要获取该值,请使用

(YourType) sp.getSelectedItem();

其中YourType是您希望获得的值的类型。如果是Long,请将其投放到Long

答案 2 :(得分:0)

定义一个类变量(此处为String selectedMonth)并在以下方法中为其赋值,然后在intent中使用此变量

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

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

        }

答案 3 :(得分: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);