@Override public boolean onNavigationItemSelected(int itemPosition, long itemId) { String previous = mViewPagerAdapter.getSelectedPulseTarget(); getSupportActionBar().setSelectedNavigationItem(itemPosition); mViewPagerAdapter.setSelectedPulseTarget(mSpinnerAdapter.getItem(itemPosition)); if (!previous.equals(mSpinnerAdapter.getItem(itemPosition))) { Log.d(LOG_TAG, "Switching chapter!"); mViewPagerAdapter.notifyDataSetChanged(); } return true; }
private void initSpinner() { Collections.sort(mPulseTargets); mPulseTargets.add(0, "Global"); mViewPagerAdapter.setSelectedPulseTarget(mPulseTargets.get(0)); mSpinnerAdapter.clear(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { mSpinnerAdapter.addAll(mPulseTargets); } else { for (String item : mPulseTargets) { mSpinnerAdapter.add(item); } } mViewPager.setAdapter(mViewPagerAdapter); mIndicator.setViewPager(mViewPager); }