내 MainActivity :새 활동 시작을위한이 코드가 왜 작동하지 않습니까?
public class MainActivity extends Activity {
public final static String EXTRA_MESSAGE = "com.example.hello.MESSAGE";
private EditText text1;
private EditText text2;
private Button btn1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
text1 = (EditText) findViewById(R.id.editText1);
text2 = (EditText) findViewById(R.id.editText2);
btn1 = (Button) findViewById(R.id.button1);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendMessage(v);
}
});
}
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
Intent intent = new Intent(this, MessageActivity.class);
String message = text1.getText().toString() + " " + text2.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);
}
}
내 MessageActivity :
버튼 레이아웃 파일에 이런 식으로 선언public class MessageActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_message);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
// Create the text view
TextView textView = (TextView) findViewById(R.id.textView3);
textView.setText("Hello" + message);
}
}
:
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="@+id/editText2"
android:layout_below="@+id/editText2"
android:layout_marginTop="47dp"
android:text="@string/main_button_1"
android:onClick="sendMessage" />
누구나 여기에 문제가 있는지 알 수 있습니까? 응용 프로그램이 에뮬레이터에서 문제없이 실행되지만 버튼을 클릭해도 아무런 변화가 없습니다.