I have a scenario. Clicking the button creates a new view and deletes the existing view.

In addition, the clicked button changes to a new button that turns the page over, and a new view is created for each page and the view is deleted.

When you press the Back button on the device, a view corresponding to the previous page is created and the previous view is deleted.

If this is the scenario, would it be right to add customView in activity? Or is it right to create and add each fragment?

Tell me the best way.

2 Answers

0
Ramesh Yankati On

You could create a fragment and commit setting feature fragment back stack true for reusing the existing fragment when user hits the back button.

Create a fragment --> replace new fragment as on Demand and pop up when you are done.

0
Gopal_Gupta On

if there are too many components or views which got changed on any event(onClicklistener or onBackPresssed) and then you should use Fragments and yes follow the procedure of replacing fragment or pop the fragment stack accordingly.

But if there are limited views or components which got changed like backgroud color, button text, number of button etc. then it will be better and easier to user a custom view in your Activity and handling the views, the events and Data will be easier as well in the same activity.

Hope this will help you!