我是开发 android 应用程序的初学者,我有一个作业,所以我需要你的帮助。我想将 3 个字符串从一个活动传递到第二个动作,然后在第二个活动中显示这些字符串。用户必须输入字符串。
那是我的代码,我不知道有什么问题。主.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
public class Main extends Activity {
public static final String EXTRA_MESSAGE = "com.mobile.activity4.class" ;
public static final String EXTRA_MESSAGE2 = "com.mobile.activity4.class" ;
public static final String EXTRA_MESSAGE3 = "com.mobile.activity4.class" ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
public void sendMessage(View view)
{
Intent myIntent = new Intent(this,DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message1);
EditText editText2 = (EditText) findViewById(R.id.edit_message2);
EditText editText3 = (EditText) findViewById(R.id.edit_message3);
Bundle extras = new Bundle();
String message = editText.getText().toString();
String message2 = editText2.getText().toString();
String message3 = editText3.getText().toString();
extras.putString("EXTRA_MESSAGE",message);
extras.putString("EXTRA_MESSAGE2",message2);
extras.putString("EXTRA_MESSAGE3",message3);
myIntent.putExtras(extras);
startActivity(myIntent);
}
}
`
DisplayMessageAcivity.java
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.widget.TextView;
public class DisplayMessageActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_message);
Bundle extras = getIntent().getExtras();
String message = extras.getString(Main.EXTRA_MESSAGE);
String message2 = extras.getString(Main.EXTRA_MESSAGE2);
String message3 = extras.getString(Main.EXTRA_MESSAGE3);
TextView textView = new TextView(this);
TextView textView2 = new TextView(this);
TextView textView3 = new TextView(this);
textView.setTextSize(40);
textView2.setTextSize(40);
textView3.setTextSize(40);
textView.setText(message);
textView2.setText(message2);
textView3.setText(message3);
setContentView(textView);
setContentView(textView2);
setContentView(textView3);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.display_message, menu);
return true;
}
}
请帮助我谢谢