• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Dynamically merge views

GIR

Member
Hello,

I have a situation where I need to merge dynamically created views.

I've found lots of info via google about how to do this with xml, but can it be done on the fly?

I think I just need a nudge in the right direction...

GIR
 
Ok, so after a Looooong time searching and experimenting with trying to get a dynamically created set of views to merge I decided I was flogging a dead horse.

So I've decided to use 2 views, one dynamicaly created, the other (with the merged views) from xml.

I have placed the code to call the views from a menu inflater, and the dynamically created view spings onto the display no problem.

However the xml generated view creates a force-close....
i am using
Code:
LinearLayout board = new LinearLayout(WebViewGameActivity.this);
        LayoutInflater inflater = getLayoutInflater();
        
        //submitScoreLayout.addView(inflater.inflate(R.layout.score_submitted, null));
        
        board.addView(inflater.inflate(R.layout.main, null));
        this.setContentView(board);
and have taken this from a tutorial I found over at Dynamically Changing Android Views with XML Layouts

Can anyone take a minute to shine alight for me please?
Thanks for your time,
GIR
 
Ok, I found a very simple fix for this.

i simply used
Code:
 setContentView(R.layout.main);
to call the xml view, and placed the code for the dynamic view within
Code:
public void dynamicView(){
....
}
 
Back
Top