Java tutorial
//package com.java2s; import android.support.v4.view.ViewPager; import android.view.Menu; import android.view.SubMenu; public class Main { public static void addItems2Menu(Menu menu, int idx, String nume, ViewPager vp) { final SubMenu smenu = menu.addSubMenu(0, idx, 0, nume); for (int i = 0; i < vp.getAdapter().getCount(); i++) { if (i != vp.getCurrentItem()) smenu.add(0, idx + i + 1, 0, vp.getAdapter().getPageTitle(i)); } } }