Skip to content

Instantly share code, notes, and snippets.

@malikkurosaki
Last active October 8, 2019 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save malikkurosaki/9e1aa1d74128ed24772fea44a5d5bfa5 to your computer and use it in GitHub Desktop.
Save malikkurosaki/9e1aa1d74128ed24772fea44a5d5bfa5 to your computer and use it in GitHub Desktop.
pager adapte

pager adapter

package probus.malikkurosaki.probussystem;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

public class Helper_pager_adapter extends FragmentPagerAdapter {

    private final int PAGE_COUNT = 2;
    private Context context;
    private String[] tabTitle = {"PHIS","RESTAURANT"};

    public Helper_pager_adapter(FragmentManager manager,Context context){
        super(manager);

    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        switch (position){
            case 0:
                return new NewProbus_fragment_main();
            case 1:
                return new NewProbus_fragment_menu_profile();

                default:return null;
        }
    }

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

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return tabTitle[position];
    }
}

implement

   PagerAdapter adapter = new Helper_pager_adapter(getSupportFragmentManager(), context);
        viewPager.setAdapter(adapter);

contoh xmlnya

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Activity_utama">
    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/mainToolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways"
            android:theme="@style/ToolBarStyle"
            app:title="">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Dashboard Finance Coltroller"
                    android:textSize="24sp"
                    android:textColor="@color/colorPutih"
                    android:textStyle="bold"
                    android:maxLines="1"/>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical"
                    android:gravity="center">
                    <TextView
                        android:id="@+id/tollbarPilihTanggal"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:gravity="center"
                        android:text="loading ..."
                        android:textColor="@color/colorHitam"
                        android:textStyle="bold"
                        android:paddingTop="8dp"
                        android:paddingEnd="16dp"
                        android:paddingStart="16dp"
                        android:paddingBottom="8dp"
                        android:background="@color/colorAbu"/>
                </LinearLayout>
            </LinearLayout>
        </androidx.appcompat.widget.Toolbar>
        <com.google.android.material.tabs.TabLayout
            android:id="@+id/mainTab"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed"
            app:tabGravity="fill"
            app:tabTextColor="@color/colorPutih"/>
    </com.google.android.material.appbar.AppBarLayout>
    <androidx.viewpager.widget.ViewPager
        android:id="@+id/utamaContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

    </androidx.viewpager.widget.ViewPager>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment