Wednesday, 13 July 2016

PreferenceFragment and Tabs



Hi,

currently I am developing a App.
I use the NavigationDrawer to set up a Menu (with the "Burger-Button") on the left side.

Wenn I choose a menu item, for example a PreferenceFragment i displayed.

My problem: I want to display a Tab-Layout with a PreferenceFragment in each Tab.
But I don´t know how...

In my MainActitivty-Class (AppCompatActivity) I change the content of my App (after the user clicked on a menu item) like this:

Code:


    @Override
    public boolean onNavigationItemSelected(MenuItem item) {
        FragmentTransaction fragmentTransaction = this.getFragmentManager().beginTransaction();
        int id = item.getItemId();

        // Globale Eistellungen
        if (id == R.id.nav_main_settings) {
            fragmentTransaction.replace(R.id.containerView, new MainPreferenceMenu());
            fragmentTransaction.commit();
        }
 

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }


Whereby "MainPreferenceMenu" is a PreferenceFragment.


I tried it with this tutorial: https://guides.codepath.com/android/...sing-tablayout

First Problem: I can´t set my PreferenceFragment here:

Code:


    @Override
    public Fragment getItem(int position) {
        return PageFragment.newInstance(position + 1);
    }


Because "PreferenceFragment" is the wring Class.


Also I don´t know how to set the "ViewPager" like in the Tutorial (MainActivity).


Can anybody help me?

I hope my Problem is clear.



No comments:

Post a Comment