1

私の質問を非常に明確でわかりやすい方法で説明しようとします。

私は現在、ここで 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 内にプログラムでいくつかのローアウトを追加することです。

私が今持っています:

    SwipeView svmain=(SwipeView) findViewById(R.id.svmain);
    //View v= findViewById(R.layout.anylayout);
    svmain.addView(v);

追加したい xml がメイン レイアウトにないため、クラッシュしています。

何か案が?

4

1 に答える 1

3

ちょうど答えを見つけました:

    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);
于 2011-10-02T13:41:12.793 に答える