如何从另一个使用制表符布局的Activity启动活动?

时间:2017-01-28 19:20:41

标签: android android-intent android-tablayout

我已在我的应用中创建了tablayout,如下所示:

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_place_info);
        getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
        getSupportActionBar().setCustomView(R.layout.action_bar);

        TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
        tabLayout.addTab(tabLayout.newTab().setText("الموقع"));
        tabLayout.addTab(tabLayout.newTab().setText("تفاصيل التصنيف"));
        tabLayout.addTab(tabLayout.newTab().setText("ساعات العمل"));
        tabLayout.addTab(tabLayout.newTab().setText("المتطلبات"));
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

        final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
        final PagerAdapter adapter = new PagerAdapter
                (getSupportFragmentManager(), tabLayout.getTabCount());
        viewPager.setAdapter(adapter);
        viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
        viewPager.setCurrentItem(4);
        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewPager.setCurrentItem(tab.getPosition());

                int position = tab.getPosition();
                switch(position){
                    case 0:
                        break;
                    case 1:
                        break;
                    case 2:
                        break;
                    case 3:
                        break;
                }

            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

页面适配器是:

public class PagerAdapter extends FragmentStatePagerAdapter {
int mNumOfTabs;

public PagerAdapter(FragmentManager fm, int NumOfTabs) {
    super(fm);
    this.mNumOfTabs = NumOfTabs;
}

@Override
public Fragment getItem(int position) {

    switch (position) {
        case 0:
            LocationInfoFragment tab1 = new LocationInfoFragment();
            return tab1;
        case 1:
            RankInfoFragment tab2 = new RankInfoFragment();
            return tab2;
        case 2:
            WorkingHoursInfoFragment tab3 = new WorkingHoursInfoFragment();
            return tab3;
        case 3:
            WorkingHoursInfoFragment tab4 = new WorkingHoursInfoFragment();
            return tab4;
        default:
            return null;
    }
}

@Override
public int getCount() {
    return mNumOfTabs;
}
}

我知道当我想开始一项活动时,我必须使用Intent,如下所示:

Intent processesListAcitivity = new Intent(getApplicationContext(), ProcessesListAcitivity.class);
            startActivity(processesListAcitivity);

我的问题是把它放在哪里:

在第一个类的switch中,还是在页面适配器中?!

1 个答案:

答案 0 :(得分:0)

[10:12:53] Starting 'sass'...
   [10:12:53] Starting 'watch'...
   [10:12:54] Finished 'watch' after 173 ms
   [10:12:54] 'sass' errored after 442 ms
    EPERM: operation not permitted, chmod '/the file path/'

}

// Include gulp
var gulp = require('gulp');

// Include Our Plugins
var sass = require('gulp-sass');
var plumber = require('gulp-plumber');
var cleanCSS = require('gulp-clean-css');
var sourcemaps = require('gulp-sourcemaps');


var sassOptions = {
    errLogToConsole: true,
    outputStyle: 'nested' // Styles: nested, compact, expanded, compressed
};

// Compile Sass file to CSS, and reload browser(s).
gulp.task('sass', function() {
    return gulp.src('includes/scss/*.scss')
        .pipe(plumber())
        .pipe(sourcemaps.init())
        .pipe(sass.sync(sassOptions))
        .pipe(sass.sync().on('error', sass.logError))
        .pipe(sourcemaps.write())
        .pipe(gulp.dest('includes/css'));
});

gulp.task('minify-css', function() {
  return gulp.src('includes/css/*.css')
    .pipe(sourcemaps.init({loadMaps: true}))
    .pipe(cleanCSS({compatibility: 'ie8'}))
    .pipe(sourcemaps.write())
    .pipe(gulp.dest('includes/css'));
});

// Watch Files For Changes
gulp.task('watch', function() {
  gulp.watch('includes/scss/**/*.scss', ['sass']);
});

// Default Task
//gulp.task('serve', ['sass', 'minify-css', 'watch']);
gulp.task('serve', ['sass', 'watch']);

}