Stacktrace Explanation:
First of all, the wrong line:
gridViewPager.addView(inflater.inflate(R.layout.selector_generic, stub));
inflate(int resource, ViewGroup root)
with root!=null matches
inflate(int resource, ViewGroup root, boolean attachToRoot) with the last argument true .
Thus, according to the documentation , it will inflate the view from resource and attach it to the root →, and then return the root.
this will try to bind the newly inflated view to stub , and then try to attach stub (the result from inflate() with the specified root ) to gridViewPager . But the stub already has a parent (it is already tied to the hierarchy of representations in your activity). So this is stacktrace explanation :)
Please note that you should not add views to the gridViewPager using the .addView() methods - you must do this through the adapter, and this line should be deleted.
GridPagerAdapter example:
Here is a simple implementation for the GridPagerAdapter ;
private class MyGridViewPagerAdapter extends GridPagerAdapter { @Override public int getColumnCount(int arg0) { return 2; } @Override public int getRowCount() { return 2; } @Override protected Object instantiateItem(ViewGroup container, int row, int col) { final View view = LayoutInflater.from(getApplicationContext()).inflate(R.layout.grid_view_pager_item, container, false); final TextView textView = (TextView) view.findViewById(R.id.textView); textView.setText(String.format("Page:\n%1$s, %2$s", row, col)); container.addView(view); return view; } @Override protected void destroyItem(ViewGroup container, int row, int col, Object view) { container.removeView((View)view); } @Override public boolean isViewFromObject(View view, Object object) { return view==object; } }
The contents of grid_view_pager_item.xml :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp"> <TextView android:id="@+id/textView" android:layout_width="match_parent" android:layout_height="100dp" android:layout_gravity="center_vertical" android:gravity="center" android:background="#4400ff00" android:textColor="#000000" android:textSize="26sp"/> </FrameLayout>
Here is the final result of a 2x2 grid. Two screens are stationary, and two are shown on half-scroll pages :)

Looking for more?
This is just an example of using the standard GridPagerAdapter . If you want a more advanced one, using FragmentGridPagerAdapter , CardFragments and background pages - see the gridViewPager example located in the platform samples:
{sdk_root}/samples/android-20/wearable/GridViewPager