Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in Using without Pager #11

Open
Rudra-n-khatri opened this issue Mar 31, 2019 · 1 comment
Open

Error in Using without Pager #11

Rudra-n-khatri opened this issue Mar 31, 2019 · 1 comment

Comments

@Rudra-n-khatri
Copy link

How can i use this without pager.i tried to add tabs using addTab method and later tried using addOntabselected Listener but its showing an error.I am using below code to do so. Is there any other way of doing the same thing or is there something wrong with my code ?

DachshundTabLayout navigationTabStrip = (DachshundTabLayout) view.findViewById(R.id.tablayout);
    navigationTabStrip.addTab(new TabLayout.Tab().setText("Pug"),1,true);
    navigationTabStrip.addTab(new TabLayout.Tab().setText("Bulldog"),2);
    navigationTabStrip.addTab(new TabLayout.Tab().setText("Beagle"),3);

with a addontabselectedlistener

navigationTabStrip.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            Toast.makeText(getContext(), tab.getText(), Toast.LENGTH_SHORT).show();
        }

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

        }

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

        }
    });

its showing an error

java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setContentDescription(java.lang.CharSequence)' on a null object reference
at com.google.android.material.tabs.TabLayout$Tab.setText(TabLayout.java:1846)

@sunilitechnotion
Copy link

sunilitechnotion commented Dec 23, 2019

If you want to use it without viewpager then use it like this way

dachshundTabLayout.addTab(dachshundTabLayout.newTab().setText("Tab 1"));
dachshundTabLayout.addTab(dachshundTabLayout.newTab().setText("Tab 2"));
dachshundTabLayout.addTab(dachshundTabLayout.newTab().setText("Tab2"));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants