実行時にボタンのテキストを変更できる簡単な例を書きたいと思います。
基本的に、「EditText」ビューからテキストを抽出し、ボタン「OnClick」イベントの内容を入力しようとしています。
ただし、システムはクラッシュします。
/** Called when the user clicks the Send button */
public void sendMessage(View view) {
// Do something in response to button
Button btn = (Button) findViewById(R.id.button_message);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
btn.setText(message);
}
私は何を間違っていますか?
a) この目的のためにボタンにリスナーを登録する必要がありますか? b) これは別の「アクティビティ」ですか? このためにインテントを作成する必要がありますか?