android - One xml to many java file? -
I have two activities that are called Home and Options. There are 6 buttons in the Home: Doctor - Appointments ... etc Options include 3 buttons: Add - Edit / Delete - List.
The option is a normal layout which means that I have doctors and appointments. But the problem is that I want to write on the button "add doctor - option / doctor - list doctor" options.xml if the buttons pressed in the home were doctors and "add appointment - edit / delete appointments list appointments" "In Options.xml if the button pressed in the home was appointment.
The point is to reduce the number of activities, so instead of creating 6 activities with the same format, can I just write text on the button Previous Activity? Is this possible?
You can send information with the intention of starting a new activity.
Click DocClick on Public Zero (see V) {intent intention = new intention (this, next activity category); Intent.putExtra ("button_text_1", "Add a doctor"); Intent.putExtra ("button_text_2", "Edit / Delete Doctor"); Intent.putExtra ("button_text_3", "list doctor"); StartActivity; } Click on Appointments on Public Zero (see V) {intent intention = new intention (this, next activity category); Intent.putExtra ("button_text_1", "Add Placement"); Intent.putExtra ("button_text_2", "edit / delete appointment"); Intent.putExtra ("button_text_3", "list appointment"); StartActivity; }
Then you can find this information in your new activity and set the text of your button:
Bundle Extras = Milentant () . 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 only send a string to indicate which button triggered the activity
intent .putExtra ("type", "doctor")
and then check ik in your other activity:
switch (getIntent (.) GetExtras (). GetString ("Type")) {Case "Doctor": Button 1. Set Text (R. string.doc); break; Case "Appointment": Button 1 .Set Text (R. String Appointment); break; }
Comments
Post a Comment