mardi 26 mai 2015

How to use an Intent in MenuItems to open a new activity in android?

I am using viewPager in my slide show,it has got 3 menu items namely action_previous,action_next and action_finish......these menuitems are at the bottom and when the slide show starts then previous and next menu item is seen then when we click these and when we reach at the end of the slideshow of the viewpager,we get like this:

So my question here is how to go to an another activity from this menu item>"Finish" using intent??? my codes for the slide show for menu are as follows:

public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu_tutorial, menu);



    menu.findItem(R.id.action_previous).setEnabled(mPager.getCurrentItem() > 0);

    // Add either a "next" or "finish" button to the action bar, depending on which page
    // is currently selected.
    MenuItem item = menu.add(Menu.NONE, R.id.action_next, Menu.NONE,
            (mPager.getCurrentItem() == mPagerAdapter.getCount() - 1)
                    ? R.string.action_finish
                    : R.string.action_next);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);

    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.home:
            // Navigate "up" the demo structure to the launchpad activity.
            // See http://ift.tt/HxQCh0 for more.
            NavUtils.navigateUpTo(this, new Intent(this, MainActivity.class));
            return true;

        case R.id.action_previous:
            // Go to the previous step in the wizard. If there is no previous step,
            // setCurrentItem will do nothing.
            mPager.setCurrentItem(mPager.getCurrentItem() - 1);
            return true;


        case R.id.action_next:


            // Advance to the next step in the wizard. If there is no next step, setCurrentItem
            // will do nothing.
            mPager.setCurrentItem(mPager.getCurrentItem() + 1);
            return true;
}

    return super.onOptionsItemSelected(item);
}

Aucun commentaire:

Enregistrer un commentaire