简体   繁体   English

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

[英]Android spinner set item activity launch

I have 2 activities in my android application, Activity A which has a List View of objects that when I click displays the details of that object in Activity B. Activity B is the same activity in which objects are added in the first place with a basic input form layout. 我的Android应用程序中有2个活动,活动A具有对象的列表视图,当我单击该对象时,将在活动B中显示该对象的详细信息。活动B是相同的活动,其中对象首先添加了基本输入表单布局。

I am receiving the information about an object from Activity A using .getSerializableExtra() from an Intent in Activity A. 我从活动A的Intent使用.getSerializableExtra()从活动A接收有关对象的信息。

I can retrieve the data correctly for my edit texts such as the name variable which is input using an edit text : 我可以正确检索编辑文本的数据,例如使用编辑文本输入的name变量:

et_medicationName.setText(med.getMedicationName());

But cannot work out how to do the same for my Spinner ? 但是无法弄清楚如何为Spinner做同样的事情吗?

So I set the spinner item, along with other fields, on Activity B and save the object which appears in my list view on Activity A (as the Title only) but how do I retrieve the selected spinner item when I click a List Item on Activity A to view it again in Activity B. 因此,我在活动B上设置了微调器项目以及其他字段,并在活动A的列表视图中保存了该对象(仅作为标题),但是当我单击列表上的列表项时如何检索选定的微调器项目活动A,以便在活动B中再次查看。

Here is my Serializable code which may be of use: 这是我可能使用的可序列化代码:

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? 
    }

I also have a getter/setter set up for the spinner. 我还为微调器设置了一个吸气剂/吸气剂。

Thanks for any help! 谢谢你的帮助!

Please try this code. 请尝试此代码。 Hope it should helpful for you. 希望对您有帮助。 Thanks 谢谢

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

For Pass Value into Intent 传递价值到意图

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

For Getting Value from Intent. 为了从意图中获得价值。

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

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

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