새로운 활동을 시작하려는 의도로 정보를 보낼 수 있습니다.
public void onDoctorClick(View v) {
Intent intent = new Intent(this, nextActivity.class);
intent.putExtra("button_text_1", "Add doctor");
intent.putExtra("button_text_2", "Edit/Delete doctor");
intent.putExtra("button_text_3", "List doctor");
startActivity(intent);
}
public void onAppointmentClick(View v) {
Intent intent = new Intent(this, nextActivity.class);
intent.putExtra("button_text_1", "Add appointment");
intent.putExtra("button_text_2", "Edit/Delete appointment");
intent.putExtra("button_text_3", "List appointment");
startActivity(intent);
}
그런 다음 당신은 당신의 새로운 활동에이 정보를 얻을하고 버튼의 텍스트를 설정할 수 있습니다
Bundle extras = getIntent().getExtras();
button1.setText(extras.getString("button_text_1"));
button2.setText(extras.getString("button_text_2"));
button3.setText(extras.getString("button_text_3"));
편집 당신은 또한 시작 어떤 버튼을 표시하는 하나의 문자열을 보낼 수 있습니다
을 활동
intent.putExtra("type", "doctor")
두 번째 활동에서 ik를 확인하십시오 :
switch(getIntent().getExtras().getString("type")) {
case "doctor":
button1.setText(R.string.doctor);
break;
case "appointment":
button1.setText(R.string.appointment);
break;
}
작동합니다. 감사 ! – user3552658
@ user3552658 여러분을 환영합니다. 제 대답을 수락하는 것을 잊지 마십시오. – Robbe
내 응용 프로그램을 여러 언어로 만들려고하기 때문에 나는 다음과 같은 문자열에서 메시지를 가져 오려고했습니다. intent.putExtra ("button_text_1", R.string.apppointment); 그러나 이렇게하면 메시지가 나타나지 않습니다. 그게 해결책이야? – user3552658