Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.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
Android 如何将editText中的字符串用作其他活动中的显示文本视图?_Android_Eclipse - Fatal编程技术网

Android 如何将editText中的字符串用作其他活动中的显示文本视图?

Android 如何将editText中的字符串用作其他活动中的显示文本视图?,android,eclipse,Android,Eclipse,我想在新活动中使用在edittext中键入的字符串作为textview sub6 = (EditText)findViewById(R.id.editText16); txt6 = (TextView)findViewById(R.id.textView25); subject = (String) sub6.getText().toString(); txt6.setText(getResources().getString(R.id.editT

我想在新活动中使用在
edittext
中键入的字符串作为
textview

sub6 = (EditText)findViewById(R.id.editText16);
        txt6 = (TextView)findViewById(R.id.textView25);
        subject = (String) sub6.getText().toString();
        txt6.setText(getResources().getString(R.id.editText16));

我用过这个代码。但是没有用。您能帮助我吗?

您可以使用Bundle发送字符串

Intent i=new Intent(A.this, B.class);                
            Bundle b = new Bundle();
            b.putString("name", sub6.getText().toString());           
            i.putExtras(b);
            startActivity(i);
在接收活动中:

Bundle extras = getIntent().getExtras(); 
String text = extras.getString("name");
我是这样做的:

EditText sub6 = (EditText) findViewById(R.id.edittext16);
TextView txt6 = (TextView) findViewById(R.id.textview25);
String subject = sub6.getText().toString();
txt6.setText(subject);

你做了很多不必要的造型。就像你的第三行把一个字符串转换成一个字符串。这是没有用的。另外,在声明对象类型(如String、EditText等)之前,请先声明它们。

在MainActivity中,使用intent发送字符串

sub6 = (EditText)findViewById(R.id.editText16);
txt6 = (TextView)findViewById(R.id.textView25);
subject = sub6.getText().toString();
Intent in=new Intent(FirstActivity.this,SecondActivity.class);
in.putExtra("key",subject);
startActivity(in);
在第二个活动中,使用getIntent()接收意图,并使用键getStringExtra()接收字符串

Intent in=getIntent();
String s=in.getStringExtra("key");
txt6.setText(s);