@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); int childCount = getChildCount(); for (int i = 0; i < childCount; i++) { final int position = i; getChildAt(i) .setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { setClickedViewChecked(position); if (mViewPager != null) { mViewPager.setCurrentItem(position, false); } } }); } }