OnTabselected ishlamayapti

Tablayout va viewpagerni o'z ichiga oladigan xml formatim bor. Ichki jadvalga biriktirilgan tomoshabin bilan fragmentda qo'shilaman va qismlarni almashtirish bilan bir qatorda o'zgarishlarni o'zgartirishni xohlayman.

<?xml version="1.0" encoding="utf-8"?>


    
    
    


Java fayllari:

package com.example.eventor;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;


import com.example.eventor.tabfragments.CalanderFragment;
import com.example.eventor.tabfragments.HomeFragments;
import com.example.eventor.tabfragments.SearchFragment;
import com.example.eventor.tabfragments.UserFragment;

public class TabFragment extends Fragment implements ActionBar.TabListener {
    public static TabLayout tabLayout;
    public static ViewPager viewPager;
    public static int int_items = 4;
    private int[] tabIcons = new int[]{

            R.drawable.ic_home_outline_white_48dp,
            R.drawable.ic_date_range_black_48dp,
            R.drawable.ic_search_black_48dp,
            R.drawable.ic_person_outline_black_48dp

    };
    FragmentAdapter fr = new FragmentAdapter(getFragmentManager());

    public TabFragment() {

    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View x = inflater.inflate(R.layout.tablayout,container,false);
        tabLayout = (TabLayout) x.findViewById(R.id.tabs);
        viewPager = (ViewPager) x.findViewById(R.id.pager);
        tabLayout.setupWithViewPager(viewPager);
        viewPager.setAdapter(new FragmentAdapter(getChildFragmentManager()));

        tabLayout.getTabAt(0).setIcon(tabIcons[0]);
        tabLayout.getTabAt(1).setIcon(tabIcons[1]);
        tabLayout.getTabAt(2).setIcon(tabIcons[2]);
        tabLayout.getTabAt(3).setIcon(tabIcons[3]);
        return x;
    }

    @Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {

        viewPager.setCurrentItem(tab.getPosition(),true);
    }

    @Override
    public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) {

    }

    @Override
    public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) {

    }

    public class FragmentAdapter extends FragmentPagerAdapter {

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "home";
                case 1:
                    return "calander";
                case 2:
                    return "search";
                case 3:
                    return "profile";

            }

     return null;
        }


        public FragmentAdapter(FragmentManager fm) {
            super(fm);

        }


        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return new HomeFragments();
                case 1:
                    return new CalanderFragment();
                case 2:
                    return new SearchFragment();
                case 3:
                    return new UserFragment();
            }
            return null;
        }

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


    }
}

Yorliqlarni bosgan holda tegishli qismlarga bormayapti. Ammo bu qismlar almashinuvi yaxshi. Rahmat

0
Yorliqlar uchun boshlang'ich nuqtasi sifatida android studio shablonini ishlatishni tavsiya qilaman
qo'shib qo'ydi muallif humazed, manba
Yorliqlar uchun boshlang'ich nuqtasi sifatida android studio shablonini ishlatishni tavsiya qilaman
qo'shib qo'ydi muallif humazed, manba

6 javoblar

Buni harakat qilib ko'ring: XML-da tablayout viewpager -ni quyida kiriting. android: layout_below = "@ id/tabs"

 <?xml version="1.0" encoding="utf-8"?>



    


    



in Code:use this instead of ActionBar.TabListener in your onCreate()

 tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener()
    {
        @Override
        public void onTabSelected(TabLayout.Tab tab)
        {
            viewPager.setCurrentItem(tab.getPosition());
        }

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

        }

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

        }
    });
0
qo'shib qo'ydi
Sizning kodingiz ishlaydi, lekin men pastki qismidagi tablarni istayman. Bu kod yaxshi emas.
qo'shib qo'ydi muallif Mohit Yadav, manba
Ko'p rahmat, hozir u ishlaydi. Iltimos, nima uchun ActionBar.TabListener ishlamayotganini aytib bering
qo'shib qo'ydi muallif Mohit Yadav, manba
Mening dizayn ko'rinishida ichki oynalar pastki qismida ko'rsatiladi
qo'shib qo'ydi muallif rafsanahmad007, manba
Harakat satri yorliqlarini tinglovchisi Rasmiy Doc dan foydalanilmaydi va sta javob bering
qo'shib qo'ydi muallif rafsanahmad007, manba

Buni harakat qilib ko'ring: XML-da tablayout viewpager -ni quyida kiriting. android: layout_below = "@ id/tabs"

 <?xml version="1.0" encoding="utf-8"?>



    


    



in Code:use this instead of ActionBar.TabListener in your onCreate()

 tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener()
    {
        @Override
        public void onTabSelected(TabLayout.Tab tab)
        {
            viewPager.setCurrentItem(tab.getPosition());
        }

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

        }

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

        }
    });
0
qo'shib qo'ydi
Sizning kodingiz ishlaydi, lekin men pastki qismidagi tablarni istayman. Bu kod yaxshi emas.
qo'shib qo'ydi muallif Mohit Yadav, manba
Ko'p rahmat, hozir u ishlaydi. Iltimos, nima uchun ActionBar.TabListener ishlamayotganini aytib bering
qo'shib qo'ydi muallif Mohit Yadav, manba
Mening dizayn ko'rinishida ichki oynalar pastki qismida ko'rsatiladi
qo'shib qo'ydi muallif rafsanahmad007, manba
Harakat satri yorliqlarini tinglovchisi Rasmiy Doc dan foydalanilmaydi va sta javob bering
qo'shib qo'ydi muallif rafsanahmad007, manba

Buni harakat qilib ko'ring: XML-da tablayout viewpager -ni quyida kiriting. android: layout_below = "@ id/tabs"

 <?xml version="1.0" encoding="utf-8"?>



    


    



in Code:use this instead of ActionBar.TabListener in your onCreate()

 tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener()
    {
        @Override
        public void onTabSelected(TabLayout.Tab tab)
        {
            viewPager.setCurrentItem(tab.getPosition());
        }

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

        }

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

        }
    });
0
qo'shib qo'ydi
Sizning kodingiz ishlaydi, lekin men pastki qismidagi tablarni istayman. Bu kod yaxshi emas.
qo'shib qo'ydi muallif Mohit Yadav, manba
Ko'p rahmat, hozir u ishlaydi. Iltimos, nima uchun ActionBar.TabListener ishlamayotganini aytib bering
qo'shib qo'ydi muallif Mohit Yadav, manba
Mening dizayn ko'rinishida ichki oynalar pastki qismida ko'rsatiladi
qo'shib qo'ydi muallif rafsanahmad007, manba
Harakat satri yorliqlarini tinglovchisi Rasmiy Doc dan foydalanilmaydi va sta javob bering
qo'shib qo'ydi muallif rafsanahmad007, manba

I suggest you use android studio template for Tabbed activity as starting point. File>>new>>acitity>>Tabbed activity

enter image description here

enter image description here

0
qo'shib qo'ydi

I suggest you use android studio template for Tabbed activity as starting point. File>>new>>acitity>>Tabbed activity

enter image description here

enter image description here

0
qo'shib qo'ydi

I suggest you use android studio template for Tabbed activity as starting point. File>>new>>acitity>>Tabbed activity

enter image description here

enter image description here

0
qo'shib qo'ydi