android - One xml to many java file? -
i have 2 activities called home , options. home contains 6 buttons : doctors - appointments...etc options contains 3 buttons : add together - edit/delete - list.
options mutual layout means want open when pressing on doctors , appointments. problem want write on buttons respectively "add doc - edit/delete doc - list doctor" in options.xml if pressed button in home doctors , "add appointment - edit/delete appointment - list appointment" in options.xml if pressed button in home appointment.
the point cut down number of activities instead of creating 6 activities same format, can write text in buttons depending on previous activity? possible ?
you can send info intent start new activity.
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); }
then can info in new activity , set text of buttons:
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"));
edit
you can send 1 string indicate button started activity
intent.putextra("type", "doctor")
and check ik in sec activity:
switch(getintent().getextras().getstring("type")) { case "doctor": button1.settext(r.string.doctor); break; case "appointment": button1.settext(r.string.appointment); break; }
android
No comments:
Post a Comment