繁体   English   中英

Android微调器设置项目活动启动

[英]Android spinner set item activity launch

我的Android应用程序中有2个活动,活动A具有对象的列表视图,当我单击该对象时,将在活动B中显示该对象的详细信息。活动B是相同的活动,其中对象首先添加了基本输入表单布局。

我从活动A的Intent使用.getSerializableExtra()从活动A接收有关对象的信息。

我可以正确检索编辑文本的数据,例如使用编辑文本输入的name变量:

et_medicationName.setText(med.getMedicationName());

但是无法弄清楚如何为Spinner做同样的事情吗?

因此,我在活动B上设置了微调器项目以及其他字段,并在活动A的列表视图中保存了该对象(仅作为标题),但是当我单击列表上的列表项时如何检索选定的微调器项目活动A,以便在活动B中再次查看。

这是我可能使用的可序列化代码:

Serializable currentMed = getIntent().getSerializableExtra("Med");
    if(currentMed != null)
    {
        Medication med = (Medication)currentMed;
        et_medicationName.setText(med.getMedicationName());

        //Get Medication Type from selected Spinner item here? 
    }

我还为微调器设置了一个吸气剂/吸气剂。

谢谢你的帮助!

请尝试此代码。 希望对您有帮助。 谢谢

Spinner spinnername1 = (Spinner) findViewById(R.id.spinner1);
String mStr = spinnername1.getSelectedItem().toString();

传递价值到意图

Intent mIntent = new Intent(CurrentActivity.this, NextActivity.class);
mIntent.putExtra("Value", mStr);
startActivity(mIntent);

为了从意图中获得价值。

Bundle bdl = getIntent().getExtras();
String mValue = bdl.getString("Value");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM