1

I'd like to know if it's possible to adapt my actual tabs to create swipable tabs without using fragments.

Right now I have non-swipable tabs (each tab contain an endless list : NewsList).

Here's the code I use for my non-swipable tabs :

tabHost = (TabHost)this.findViewById(R.id.scrollTabs);
// Avant d’ajouter des onglets, il faut impérativement appeler la méthode
    // setup() du TabHost
LocalActivityManager mLocalActivityManager = new LocalActivityManager(this, false);
mLocalActivityManager.dispatchCreate(savedInstanceState);
tabHost.setup(mLocalActivityManager);

// Ajoute un onglet pour chaque catégorie de news
tabNewslist = new NewsList[NewsCategory.values().length];
View tabView;

for (int i = 0; i < NewsCategory.values().length; i++) {
    tabView = createTabView(tabHost.getContext(), NewsCategory.getValueAt(i).getName());

    tabNewslist[i] = new NewsList(this, new LinkedList<Item>(), IdUrlRss.NEWSLIST, NewsCategory.getValueAt(i));
    tabHost.addTab(tabHost.newTabSpec(NewsCategory.getValueAt(i).getName()).setIndicator(tabView).setContent(tabNewslist[i]));
}

And here's the XML layout :

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
         android:id="@+id/tabHost"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">

    <LinearLayout android:orientation="vertical"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent">

        <HorizontalScrollView android:layout_width="fill_parent"
                          android:layout_height="wrap_content"
                          android:fillViewport="true"
                          android:scrollbars="none">                        
            <TabWidget android:id="@android:id/tabs"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content" />

        </HorizontalScrollView>

        <FrameLayout android:id="@android:id/tabcontent"
                 android:layout_width="fill_parent"
                 android:layout_height="fill_parent" />

        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />

    </LinearLayout>
</TabHost>

I also tried to create a PagerAdapter for NewsList but I failed.

4

1 回答 1

2

你可以,通过使用

第二个选项更好,因为您可以在启动器中使用几乎任何东西作为“页面”(就像 android 主屏幕一样)

也就是说,只使用片段然后在其上使用ViewPager会容易得多:)

于 2012-07-13T19:31:02.690 回答