2

I am in the process of creating an app with the following functionality. The Main activity is a Tabbed activity with three fragments. The middle fragment consists of a ListView. When you select the listView item it will allow you to do one of two things:

  1. Edit the layout, you can add buttons, switches, text boxes, ect.
  2. If a layout is created, you can swipe to the first tab where the layout will be loaded with all the custom views the user added.

I would like to know how I can save each ViewGroup so the user can access them and edit them as they please. I do not think this can be done with SavedStated because it will be across different activities, that is why I need a way to save/load them.

I have one fragment that allows you to customize the layout. I would like to only save the ViewGroup with all the children. So instead of having 10 different XML layouts, you would have 1 XML layout with 10 different ViewGroups that can be inserted dynamically as the different ListView item is selected.

It cannot be an image of the layout, I need to have the functionality of all the buttons and switches when I tab over to the View and the user needs to be able to edit their layout when they please.

Ravi
  • 34,851
  • 21
  • 122
  • 183
srtmonkey
  • 85
  • 9

1 Answers1

1

I think you need to create model for all of you View. For example ModelButton - is model of you button may have next code:

public class ModelButton implements Serializable{
    private String text;
   private Bitmap bgResource;
   private int width;
   private int height
   public ModelButton(final String text, final Bitmap bgResource, final int width, final int height) {
      this.text = text;
      this.bgResource = bgResource;
      this.width = width;
      this.height = height;
   }
}

all of your model must implements Serializable interface to allow pass it into Intent. Also you need come up the way to store width and heigth of Views.

It is not simple way, but as I know is no way to pass ViewGroup or View between activities

Konstantin
  • 174
  • 7
  • That is what I was afraid of. I guess I am going to have to rethink how I build this app. What if I created multiple fragments and inflated each one according to the selection the user made. Would there be a way to save that fragment after it has been customized? – srtmonkey May 20 '16 at 03:44
  • Yes, you can create fragment with created ViewGroup as content. But still you need the way to store you Views when onPause - onResume fragtment methods called – Konstantin May 20 '16 at 04:11