Java tutorial
//package com.java2s; /* * XPerience Kernel Tweaker - An Android CPU Control application * Copyright (C) 2011-2015 Carlos "Klozz" Jesus <TeamMEX@XDA-Developers> * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see <http://www.gnu.org/licenses/>. */ import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.support.v4.view.ViewPager; import java.util.ArrayList; import java.util.List; public class Main { public static void getTabList(String strTitle, final ViewPager vp, Activity activity) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity); alertDialogBuilder.setTitle(strTitle); List<String> listItems = new ArrayList<String>(); for (byte i = 0; i < vp.getAdapter().getCount(); i++) { listItems.add(vp.getAdapter().getPageTitle(i).toString()); } alertDialogBuilder.setItems(listItems.toArray(new CharSequence[listItems.size()]), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { vp.setCurrentItem(which); } }).show(); } }