Reputation: 1424
I have an activity, which is a Form containing edit fields.
With in my activity I have an "New Form" Button. on click of the Button I need to open same activity and need to change the button text to "Switch Form". Which I am able to do.
Now on click of "switch form" button i need to open the previously saved Form. How can i do that.
I guess i need to create 2 instances of Activity, but I have no idea how to do that. can some one please guide me on that.
Thanks :)
Upvotes: 1
Views: 845
Reputation: 14850
Rather than creating two activities for the same purpose, why don't you use fragments instead? This case-scenario is the best fit for a re-usable fragment. You can replace fragments seamlessly from within the host activity, pop them from the back stack by just using the "Back" button, etc.
There are many ways to get around your problem, but using a fragment is by far a more elegant and scalable solution
Upvotes: 2
Reputation: 4701
I feel you dont need to create two instance of activity, you need to create two form instances rather. When "New Form" is clicked, show corresponding form instance values, and same applicable for "Switch Form"
So, you will be having two layouts for both the forms and one fragment. Whatever action is set, check which layout is applicable for that action and set the layout in the fragment.
Upvotes: 0
Reputation: 685
Rather than going for 2 activities I suggest you use one activity with a framelayout where you can place fragments. On click of button you can change the text of the button and add new fragment. On back click you can go to fragment backstack and display the previous form to the user
Upvotes: 0
Reputation: 53545
You can use intent
to save the parameters when you "switch" between the form to itself. As for the button, you can create two buttons and toggle their visibility using:
buttonObj.setVisibility(View.VISIBLE);
and
buttonObj.setVisibility(View.INVISIBLE);
Upvotes: 0