long1eu / SpaceTabLayout

Not actively maintained, but PR are welcomed
1.6k stars 265 forks source link

onclicklistener reacts at the 2-nd tap #8

Closed zboing closed 7 years ago

zboing commented 7 years ago

Example:

tabLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplication(), ""+tabLayout.getCurrentPosition(),Toast.LENGTH_SHORT).show(); } });

the toast is shown when I tap the second time on an element

long1eu commented 7 years ago

I can't replicate your bug, please give me more info. On my side your code works as expected.

zboing commented 7 years ago

Samsung Galaxy S6, OS: 5.1.1, Android Studio 2.3 beta 1 compile 'eu.long1:spacetablayout:1.0.4' http://sendvid.com/pxmir5jb

public class MainActivity extends AppCompatActivity {
    SpaceTabLayout tabLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //add the fragments you want to display in a List
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(new FragmentA());
        fragmentList.add(new FragmentB());
        fragmentList.add(new FragmentC());
        fragmentList.add(new FragmentD());
        fragmentList.add(new FragmentE());

        ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
        tabLayout = (SpaceTabLayout) findViewById(R.id.spaceTabLayout);

        //we need the savedInstanceState to retrieve the position
        tabLayout.initialize(viewPager, getSupportFragmentManager(), fragmentList, savedInstanceState);

        tabLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getApplication(), ""+tabLayout.getCurrentPosition(),Toast.LENGTH_SHORT).show();
            }
        });
    }

    //we need the outState to memorize the position
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        tabLayout.saveState(outState);
        super.onSaveInstanceState(outState);
    }

}
long1eu commented 7 years ago

I still can find the problem. Can you please try it in emulator? Just use a Virtual Device that matches you S6. I'm curious if it will work.

Thanks for writing

On Dec 28, 2016 2:03 PM, "zboing" notifications@github.com wrote:

Samsung Galaxy S6, OS: 5.1.1, Android Studio 2.3 beta 1 compile 'eu.long1:spacetablayout:1.0.4' http://sendvid.com/pxmir5jb

public class MainActivity extends AppCompatActivity { SpaceTabLayout tabLayout;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //add the fragments you want to display in a List
    List<Fragment> fragmentList = new ArrayList<>();
    fragmentList.add(new FragmentA());
    fragmentList.add(new FragmentB());
    fragmentList.add(new FragmentC());
    fragmentList.add(new FragmentD());
    fragmentList.add(new FragmentE());

    ViewPager viewPager = (ViewPager) findViewById(R.id.viewPager);
    tabLayout = (SpaceTabLayout) findViewById(R.id.spaceTabLayout);

    //we need the savedInstanceState to retrieve the position
    tabLayout.initialize(viewPager, getSupportFragmentManager(), fragmentList, savedInstanceState);

    tabLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getApplication(), ""+tabLayout.getCurrentPosition(),Toast.LENGTH_SHORT).show();
        }
    });
}

//we need the outState to memorize the position
@Override
protected void onSaveInstanceState(Bundle outState) {
    tabLayout.saveState(outState);
    super.onSaveInstanceState(outState);
}

}

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/thelong1EU/SpaceTabLayout/issues/8#issuecomment-269468153, or mute the thread https://github.com/notifications/unsubscribe-auth/AI2nVrU4EKuK6Dxu4ZbtMI-NrSkDz-apks5rMlALgaJpZM4LWzZc .

zboing commented 7 years ago

it reproduces with the following emulator settings:

CPU/ABI: Google APIs Intel Atom (x86)

Target: google_apis [Google APIs] (API level 23)

Nexus 5 Lollipop API 23 Android 6.0

thanks!

long1eu commented 7 years ago

Sorry! I can't reproduce your bug. I tried 5 different devices and all work with the above code. The OnClick is called on first press.