Making a copy of the view?

I have 2 actions: A, B. Layout of Activity A, has a view group in which the user changes its contents. In Activity B, I have to show this view group again without any changes, it should be a real copy of this viewgroup, so the texts, colors, sizes, order (from children) and ... should be the same. Therefore, I cannot use Layout Inflater . Is this possible without creating classes such as children of this view group and changing properties? if I have more than two operations with different groups of views, it is very difficult to show the viewing groups of each action in the last activity.

Also, I cannot remove these view groups from my parents.

+6
source share
5 answers

If their content is the same, it makes no sense to have two different activities. You can dynamically change the content of one activity, and the behavior will be the same as the two actions. If it is really necessary, you will need to save all the necessary information in order to restore activity again and transfer it to the newly created action. Take a look.

+5
source

There is no easy way to do this. You cannot move a view between actions. Thus, you have several options:

  • create a viewGroup bitmap and show it in a new activity (does not work, you need an editable copy)
  • save the state of the presentation hierarchy in the old activity and recreate it in the new one (simplify using fragments).
  • Do not create new activity. Just change some user interface elements in the old one without touching the target ViewGroup.
+4
source

Create a class that contains the configuration of your view group. Let this configuration class contain all the information related to your ViewGroup. It will contain the texts, colors, sizes and order that the user has changed. Pass an object of this class from Activity A to Activity B and using this, reproduce the same view, inflating the same layout.

Hope this helps.

And to answer your question, there is no other easy way to do this.

+1
source

For the ViewGroup to be split, reformat it to a fragment named C. Then create fragments for the Activity A and B sections minus this common part. Then include all of these fragments in the new active activity (you will no longer need actions A and B).

Fragment A and C will be the new activity A. Fragments B and C will be the new activity B. To switch from the first state to the second, make a FragmentTransaction by adding fragment B and deleting fragment A. Remember to add this transaction to the back stack so that the return button returns you to the first state.

+1
source

Just a general doubt? why do you want to go for two actions, why not use two fragments assigned to the same view, using the basic action to store all the changes that occur in one of the fragments (View), and when the user goes to another view, just send it parameters to the second fragment. Thus, you imitate the user that these are two actions, but in reality these are just two fragments controlled by one action.

+1
source

All Articles