java - "Redraw" LinearLayout view to change option -


i'm trying change attribute custom linearlayout class, set option class with:

mybuilder option = new mybuilder.builder() .image(...) .setcardradius(...) .build()); 

than call in mainactivity

myobject obj = (myobject) findviewbyid(r.id.myobject);  obj.init(context, option); 

but if call multiple times obj.init(...) different option builder has old value setted view cannot change attribute correctly.

so question is: can reset builder o linearlayout before initializate new object?

this linearlayout.java:

public class myobject extends linearlayout{     cardview card;     imageview image;     float cardradiusattr;     view rootview;     attributeset attributeset;      public void init(final context context, final mybuilder option){         if(option != null)         {          /*         attribute xml          */             typedarray ta = context.obtainstyledattributes(attributeset, r.styleable.card, 0, 0);             try {                 cardradiusattr = ta.getdimension(r.styleable.card_c_cardradius, option.getcardradius());              } {                 ta.recycle();             }          /*         set xml object.          */             card = (cardview) findviewbyid(r.id.card);             image = (imageview) findviewbyid(r.id.image);              card.setradius(cardradiusattr);              /**              * check if option set              */             if (option.isimage() != null) {                //set image              }         }else{             log.e("initialization", "option view not initialize!");         }     }       public myobject(context context, attributeset attrs) {         super(context, attrs);         /*         inflater custom layout view.          */         layoutinflater inflater = (layoutinflater) context                 .getsystemservice(context.layout_inflater_service);         rootview = inflater.inflate(r.layout.card, this, true);         attributeset = attrs;     }       @override     protected void onfinishinflate() {         super.onfinishinflate();     }  } 

this mybuilder.java

public class mybuilder {     private int mimage;     private float mcardradius = 4f;      private mybuilder(builder builder)     {         mimage = builder.mimage;         mcardradius = builder.mcardradius;     }      public static class builder{         private int mimage;         private float mcardradius = 4f;          public builder setcardradius(float radius)         {             if(radius <= 0)             {                 log.e("cardradius", "impossible set card radius lower 0! please check it");             }             else {                 mcardradius = radius;             }             return this;         }          public builder image(int image) {              if(image == 0)             {                 log.e("image", "impossible set image 0! please check it");             }             else {                 mimage = image;             }             return this;         }          public mybuilder build() {             return new mybuilder(this);         }      }      public int getimage() {         return mimage;     }      public float getcardradius() {         return mcardradius;     } } 

i found issue.

in init method of myobject have clean view after previous use.

in particular case, first, pass 1 set of options. based on them, view adjusting visibility of controls (making button1, button2, etc. visible). when pass another set of options - have erase changes have been made before. (i.e. hide button1, button2, etc. , let view adjust visibility of controls once again)


Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -