android, adding XML Layout Views to an inflated view in a custom class -


i havent found answer on internet quite while , im asking if can me.

short: how should override addview() (or else) add views defined in xml "custom view inflated xml layout"

long: want create custom view android app, created clean subclass relativelayout. in this, let inflater load xml layout nice style.

but now, want add inside custom view, dont want add programattically (this works), xml. cant cross gap in mind find solution...

code: custom class:

public class slider extends relativelayout {      private relativelayout _innerlayout;      public slider(context context) {         super(context);         init();     }      public slider(context context, attributeset attrs) {         super(context, attrs);         init();     }      protected void init() {         layoutinflater layoutinflater = (layoutinflater) this.getcontext().getsystemservice(context.layout_inflater_service);         _innerlayout = (relativelayout) layoutinflater.inflate(r.layout.layout_r, this);      }      @override     public void addview(view child) {         //if (_innerlayout != null) _innerlayout.addview(child);         super.addview(child);     }  ... other addview's overridden in same way 

xml file using subclass:

<packagename....slider     android:id="@+id/slider1"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:background="@color/red" >         <textview             android:id="@+id/heading"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:text="heading" />          <button             android:id="@+id/button"             android:layout_width="wrap_content"             android:layout_height="wrap_content"             android:layout_alignparentright="true"             android:text="bbb" />  ... 

the textview , button added subclass... sure... after that, got 3 children in slider, textview, button , inflated layout r.layout.layout_r. want 1 child (the layout_r) button , textview in it.

as can see in addview tried add passed "view child" _innerlayout. doesnt work. android framework keeps calling addview , ends stackoverflowerror

two thing tell too:

  1. i know adding views xml doesnt call given addview, i've overriden others , looking same theres no need show them.

  2. debugger said me, addview called before _innerlayout gets inflated layout

is 2. reason?

can u me?

you can take on how inflate children custom view here (vogella tutorial).

what need is:

  1. define layout children using <merge> tag
  2. inflate layout in custom view constructor using layoutinflater.inflate(res, this, true)

Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -