Android ViewPager - Comment ajouter des boutons dans les pages?

Je suis ce lien pour faire un ViewPager http://blog.stylingandroid.com/archives/537
J'ai réussi à obtenir les différentes pages. Mais comment dois-je remplir ou à compléter ces pages avec des boutons?

instantiateItem()

Cela crée de la vue pour un poste donné. Pour un
application réelle nous serait d'utiliser un Fragment ici, ou gonfler une mise en page,
mais pour garder l'exemple simple, nous allons créer un TextView, le texte
la valeur correcte de nos titres de tableau, et l'ajouter à la ViewPager

Je veux avoir différentes fonctions des boutons sur les différentes pages. Comment dois-je faire? En utilisant les différentes mise en page? Comment puis-je mettre à la disposition au sein de la page (est-ce cela que vous appelez inflat)?

EDIT:
J'ai l'main.xml qui se compose de la ViewPager

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:weightSum="1">

    <com.viewpagerindicator.TitlePageIndicator
        android:id="@+id/indicator"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1" />        
</LinearLayout>

J'ai plusieurs autres xml qui se compose de boutons qui je tiens à le gonfler dans les différentes pages de la ViewPage. Exemple d'un fichier xml.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <Button android:layout_width="match_parent" android:text="Button 1" android:onClick="onClick" android:id="@+id/button1" android:layout_height="100dp"></Button>
    <Button android:text="Button 2" android:onClick="onClick" android:id="@+id/button2" android:layout_width="match_parent" android:layout_height="100dp"></Button>
    <Button android:text="Button 3" android:onClick="onClick" android:id="@+id/button3" android:layout_width="match_parent" android:layout_height="100dp"></Button>
    <Button android:text="Button 4" android:onClick="onClick" android:id="@+id/button4" android:layout_width="match_parent" android:layout_height="100dp"></Button>
    <Button android:text="Button 5" android:onClick="onClick" android:id="@+id/button5" android:layout_height="match_parent" android:layout_width="match_parent"></Button>

</LinearLayout>

Dans le ViewPagerAdapter.java, j'ai réussi à gonfler les différents XML dans les pages.

@Override
public Object instantiateItem( View pager, int position )
{
    //Inflate the correct layout
    LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    //layouts[] is an int[] that points to resources such as R.layout.start_page
    View inflatedView = layoutInflater.inflate(layouts[position], null);

    ((ViewPager)pager).addView(inflatedView,0);

    return inflatedView;

}

Et ce qui doit être changé pour prévenir erreur.

@Override
public void destroyItem( View pager, int position, Object view )
{
    ((ViewPager)pager).removeView( (View)view );
}

Maintenant, j'ai plusieurs boutons sur les différentes pages. Comment puis-je programme le ONCLICK de la fonction des différents boutons sur les différentes pages? Ce travail peut?

public void onClick(View v) {
        switch (v.getId()) {
        case R.id.button1:
            //do something
            break;
        case R.id.button2:
            //do something
            break;
        case R.id.button3:
            //do something
            break;
        case R.id.button4:
            //do something
            break;
        case R.id.button5:
            //do something
            break;
        }
    }
Avez-vous essayé d'ajouter des boutons dans la mise en page?
je pense que le XML est le principal organe de la ViewPager (qui est un widget) et les boutons ne peuvent pas être ajoutée à l'intérieur d'elle à droite?

OriginalL'auteur humansg | 2012-05-14