使用TabListener触发活动ActionBarSherlock [英] Using a TabListener for triggering Activities with ActionBarSherlock

查看:93
本文介绍了使用TabListener触发活动ActionBarSherlock的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些很难找到一个例子,我明白了使用ActionBarSherlock。我可以实现 TabNavigation.java 例如自带的下载。我不知道如何延长这个例子中,这样它会触发一个新的活动,但仍保持显示的选项卡。下面是我实现的例子:

I have had some trouble finding an example I understand for using ActionBarSherlock. I can implement the TabNavigation.java example that comes with the download. I'm not sure how to extend this example so that it triggers a new activity but still keeps the tabs displayed. Here's the example that I've implemented:

package com.actionbarsherlock.sample.demos;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.widget.TextView;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockActivity;

public class TabNavigation extends SherlockActivity implements ActionBar.TabListener {
    private TextView mSelected;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        setTheme(SampleList.THEME); //Used for theme switching in samples
        super.onCreate(savedInstanceState);

        setContentView(R.layout.tab_navigation);
        mSelected = (TextView)findViewById(R.id.text);

        getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        for (int i = 1; i <= 3; i++) {
            ActionBar.Tab tab = getSupportActionBar().newTab();
            tab.setText("Tab " + i);
            tab.setTabListener(this);
            getSupportActionBar().addTab(tab);
        }
    }

    @Override
    public void onTabReselected(Tab tab, FragmentTransaction transaction) {
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction transaction) {
        mSelected.setText("Selected: " + tab.getText());
    }

    @Override
    public void onTabUnselected(Tab tab, FragmentTransaction transaction) {
    }
}

我认为我需要创建一个新的监听器​​类,并传递给 .setTabListener()方法。我想和活动(不片段)要坚持,因为我有一个pretty的复杂的实施ORMLite的,我不知道如何使用ORMLite与片段呢。

I believe I need to create a new "Listener" class and pass that to the .setTabListener() method. I want to stick with Activities (not Fragments) as I have a pretty complex implementation of ORMLite and I'm not sure how to use ORMLite with Fragments yet.

我想添加一个新的标签标有档案,这会触发 ProfileActivity.class

I want to add a new tab labeled "Profile" which triggers ProfileActivity.class.

在此先感谢!

推荐答案

我想这TabListener应该与片段和FragmentTransaction工作。你必须将你的code从ProfileActivity到一个新的ProfileFragment类,并与收到的监听器的FragmentTransaction添加。

I guess that TabListener is supposed to work with Fragments and FragmentTransaction. You will have to move your code from ProfileActivity to a new ProfileFragment class and add it with the FragmentTransaction you receive by the listener.

我会建议你添加ViewPagerIndicator库中的项目,就像这个答案。一个ViewPager就像标签加上了Swype运动在它们之间进行导航。

I would suggest you to add ViewPagerIndicator library on your project, just like this answer. A ViewPager is just like tabs plus the swype movement to navigate between them.

这篇关于使用TabListener触发活动ActionBarSherlock的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆