Skip to content
This repository was archived by the owner on Jul 5, 2025. It is now read-only.
This repository was archived by the owner on Jul 5, 2025. It is now read-only.

Error in Using without Pager #11

@Rudra-n-khatri

Description

@Rudra-n-khatri

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions