Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Android应用程序之间传递“EditText”值_Java_Android_Android Activity_Android Edittext - Fatal编程技术网

Java 如何在Android应用程序之间传递“EditText”值

Java 如何在Android应用程序之间传递“EditText”值,java,android,android-activity,android-edittext,Java,Android,Android Activity,Android Edittext,我正在尝试构建一个活动,在其中我在EditText中插入一个搜索词,单击一个按钮,应用程序将打开一个不同的活动,在该活动中,我需要使用在上一个活动中插入的搜索词的值执行查询 如何将此值从以前的活动中移动并在另一个不同的活动中使用 谢谢。意图用于将数据从一个活动发送到另一个活动 使用此选项放置字符串: Intent i = new Intent(CurrentActivity.this, NextActivity.class); String searchItem= editText.get

我正在尝试构建一个活动,在其中我在EditText中插入一个搜索词,单击一个按钮,应用程序将打开一个不同的活动,在该活动中,我需要使用在上一个活动中插入的搜索词的值执行查询

如何将此值从以前的活动中移动并在另一个不同的活动中使用

谢谢。

意图用于将数据从一个活动发送到另一个活动

使用此选项放置字符串:

Intent i = new Intent(CurrentActivity.this, NextActivity.class);   
String searchItem= editText.getText().toString(); //Getting string from the editText, in your case the Search based EditText

i.putExtra("STRING_I_NEED", searchItem); // putExtra(KEY,VALUE) where KEY is used to fetch data in another activity and VALUE is the value you want to carry.

startActivity(i);
然后,要在NextActivity中检索该值,请在OnCreate中执行以下操作:

Bundle extras = getIntent().getExtras();
if (extras != null)
{
    String myParam = extras.getString("STRING_I_NEED");
}
else
{
    //..oops!
}
意图用于将数据从一个活动发送到另一个活动

使用此选项放置字符串:

Intent i = new Intent(CurrentActivity.this, NextActivity.class);   
String searchItem= editText.getText().toString(); //Getting string from the editText, in your case the Search based EditText

i.putExtra("STRING_I_NEED", searchItem); // putExtra(KEY,VALUE) where KEY is used to fetch data in another activity and VALUE is the value you want to carry.

startActivity(i);
然后,要在NextActivity中检索该值,请在OnCreate中执行以下操作:

Bundle extras = getIntent().getExtras();
if (extras != null)
{
    String myParam = extras.getString("STRING_I_NEED");
}
else
{
    //..oops!
}

转到下一个活动:

1使用将整个字符串传递给下一个活动

 intent.putExtras("Key",string);
2创建一个getter setter的单例类,通过使用该类,您可以在整个应用程序中设置和获取值


3将值保存在db中并从中读取它

移动到下一个活动:

1使用将整个字符串传递给下一个活动

 intent.putExtras("Key",string);
2创建一个getter setter的单例类,通过使用该类,您可以在整个应用程序中设置和获取值


3将值保存在db中并从中读取

使用Intent extras将任何数据传递给第二个活动。使用Intent.putExtra可以实现的最佳方式;使用Intent extras将任何数据传递给第二个活动;我建议将键固定为常量。例如:公共静态最终字符串INTENT\u PARAM\u SEARCH\u关键字=INTENT\u PARAM\u SEARCH\u关键字;这是一个例子。如果我必须让初学者更清楚地知道答案,我宁愿进一步细分;这很公平,我建议把钥匙当作一个常数。例如:公共静态最终字符串INTENT\u PARAM\u SEARCH\u关键字=INTENT\u PARAM\u SEARCH\u关键字;这是一个例子。如果我必须让初学者更清楚地知道答案,我宁愿进一步细分;这很公平