如何从一个活动将值传递给另一个机器人? [英] How to pass a value from one Activity to another in Android?
问题描述
我创建了一个带有AutuCompleteTextView [ACTV]和按钮的活动。我进入了ACTV一些文本,然后$ P $ PSS的按钮。 之后我preSS的按钮,我想活动到另一个活动。在第二个活动我只是想显示为一个TextView在ACTV进入(第一actvity的)文本。
I have created an Activity with a AutuCompleteTextView[ACTV] and button. I enter some text in the ACTV then press the button. After I press the button I want the Activity to go to another Activity. In the second Activity I just want to display the text entered in ACTV(of the first actvity) as a TextView.
我知道如何启动第二个活动是如下:
I know how to start the second activity which is as below:
Intent i = new Intent(this, ActivityTwo.class);
startActivity(i);
我有codeD此获得来自ACTV输入的文本。
I have coded this to obtain the text entered from the ACTV.
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete);
CharSequence getrec=textView.getText();
在这里我的问题是如何通过getrec(后I $ PSS的按钮p $)从第一个活动到第二。后来又免费获赠getrec中的第二个活动。
My question here is how to pass "getrec" (after I press the button) from the first Activity to the second. And later recieve "getrec" in the second activity.
请假设通过使用我所创建的事件处理程序类按钮的onClick(视图v)
Please assume that I have created the event handler class for the button by using "onClick(View v)"
推荐答案
您可以使用捆绑在Android的做同样的
You can use Bundle to do the same in Android
创建的意图:
Intent i = new Intent(this, ActivityTwo.class);
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete);
String getrec=textView.getText().toString();
//Create the bundle
Bundle bundle = new Bundle();
//Add your data to bundle
bundle.putString("stuff", getrec);
//Add the bundle to the intent
i.putExtras(bundle);
//Fire that second activity
startActivity(i);
现在你的第二个活动从包中检索数据:
Now in your second activity retrieve your data from the bundle:
//Get the bundle
Bundle bundle = getIntent().getExtras();
//Extract the data…
String stuff = bundle.getString("stuff");
这篇关于如何从一个活动将值传递给另一个机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!