brazole.com.secondtask.adapters.PagerAdapter.java Source code

Java tutorial

Introduction

Here is the source code for brazole.com.secondtask.adapters.PagerAdapter.java

Source

package brazole.com.secondtask.adapters;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import java.io.Serializable;
import java.util.List;
import brazole.com.secondtask.CrudIssue;
import brazole.com.secondtask.TabFragmentRecyclerView;
import brazole.com.secondtask.TabFragmentListView;

/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 *  pager adapter
 */

public class PagerAdapter extends FragmentStatePagerAdapter {
    private int mNumOfTabs;

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

    @Override
    public Fragment getItem(int position) {

        List issueListByType0 = CrudIssue.getIssuesByStatus(0);
        List issueListByType1 = CrudIssue.getIssuesByStatus(1);
        Bundle args = new Bundle();

        switch (position) {
        case 0:
            TabFragmentRecyclerView fragment1 = new TabFragmentRecyclerView();
            args.putSerializable("issueListByType0", (Serializable) issueListByType0);
            fragment1.setArguments(args);
            return fragment1;

        case 1:
            TabFragmentRecyclerView tab2 = new TabFragmentRecyclerView();
            args.putSerializable("issueListByType1", (Serializable) issueListByType1);
            tab2.setArguments(args);
            return tab2;

        case 2:
            return new TabFragmentListView();
        default:
            return null;
        }
    }

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