开发者

Programmatically add a new layout inside a SwipeView

开发者 https://www.devze.com 2023-04-10 16:48 出处:网络
I will try to explain my question in a very clear and understandable way. I am currently using the SwipeView here: http://jasonfry.co.uk/?id=23

I will try to explain my question in a very clear and understandable way.

I am currently using the SwipeView here: http://jasonfry.co.uk/?id=23

<uk.co.jasonfry.android.tools.ui.SwipeView  
    android:id="@+id/swipe_view"
    android:layout_width="match_parent" 
    android:layout_height="wrap_content">
                <View android:id="@+id/view1" />
                <View android:id="@+id/view2" />
                <View android:id="@+id/view3" />
</uk.co.jasonfry.android.tools.ui.SwipeView>

That'quite easy and powerful, and of course working fine.

What I would like to achieve now is to add some of my loayouts programmatically inside this SwipeView.

I have now:

    SwipeView svmain=(SwipeView) findViewById(R.id.svmain);
    //View v= findV开发者_运维百科iewById(R.layout.anylayout);
    svmain.addView(v);

That's crashing because the xml I want to add is not in my main layout.

Any idea?


Just found the answer:

    SwipeView svmain=(SwipeView) findViewById(R.id.svmain);
    LayoutInflater inflater = (LayoutInflater)   getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View view = inflater.inflate(R.layout.header, null);
    svmain.addView(view);
    View view2 = inflater.inflate(R.layout.header, null);
    svmain.addView(view2);
    View view3 = inflater.inflate(R.layout.header, null);
    svmain.addView(view3);
0

精彩评论

暂无评论...
验证码 换一张
取 消