0

I want to create a feed like the one in the facebook app, and I want to have actionbarsherlock navigation tabs that will be used to filter the feed - a tab for people, a tab for places and a tab for items.

Right now I've set it up so that each tab opens up a fragment. How can I make them open up a list view instead?

    ActionBar.Tab itemsFeedTab = actionBar.newTab();
    ActionBar.Tab peopleFeedTab = actionBar.newTab();
    ActionBar.Tab placesFeedTab = actionBar.newTab();

    Fragment itemsFeedFragment = new FeedItems();
    Fragment peopleFeedFragment = new FeedPeople();
    Fragment placesFeedFragment = new FeedPlaces();

    itemsFeedTab.setTabListener(new MyTabsListener(itemsFeedFragment));
    peopleFeedTab.setTabListener(new MyTabsListener(peopleFeedFragment));
    placesFeedTab.setTabListener(new MyTabsListener(placesFeedFragment));

    actionBar.addTab(itemsFeedTab, 0, true);
    actionBar.addTab(peopleFeedTab, 1, false);
    actionBar.addTab(placesFeedTab, 2, false);


class MyTabsListener implements ActionBar.TabListener {
    public Fragment fragment;

    public MyTabsListener(Fragment fragment){
        this.fragment = fragment;
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        // TODO Auto-generated method stub
        ft.replace(R.id.home, fragment);
    }
4

2 に答える 2

1

答えはあなたの質問に隠されています。あなたはListViewの代わりに開こうとしていますFragment

を開けListFragmentたら、完了です。

于 2013-10-22T07:49:16.120 に答える
1

フラグメントにListViews のみが含まれている場合は、使用することをお勧めしますListFragment

于 2013-10-22T07:53:27.717 に答える