Программно добавить новый макет внутри SwipeView - PullRequest
1 голос
/ 02 октября 2011

Я попытаюсь объяснить мой вопрос в очень ясной и понятной форме.

Я сейчас использую SwipeView здесь: 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>

Это довольно легко и мощнои, конечно, работает нормально.

Что бы я хотел достичь сейчас, так это программно добавить некоторые из моих раскладок внутри этого SwipeView.* Это сбой, потому что xml, который я хочу добавить, отсутствует в моем основном макете.

Есть идеи?

1 Ответ

3 голосов
/ 02 октября 2011

Только что нашел ответ:

    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);
...