我创建了一个带有 AutuCompleteTextView[ACTV] 和按钮的活动。我在 ACTV 中输入一些文本,然后按下按钮。
按下按钮后,我希望该活动转到另一个活动。在第二个活动中,我只想将在第一个活动的 ACTV 中输入的文本显示为 TextView。
我知道如何开始第二个活动,如下所示:
Intent i = new Intent(this, ActivityTwo.class);
startActivity(i);
我已对此进行编码以获得从 ACTV 输入的文本。
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete);
CharSequence getrec=textView.getText();
我的问题是如何将“getrec”(按下按钮后)从第一个活动传递到第二个活动。然后在第二个活动中收到“getrec”。
请假设我已经使用“onClick(View v)”为按钮创建了事件处理程序类
您可以使用 Bundle 在 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);
现在,在第二个活动中从捆绑包中检索数据:
//Get the bundle
Bundle bundle = getIntent().getExtras();
//Extract the data…
String stuff = bundle.getString(“stuff”);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)