Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

How to Launch a new activity from a popup menu

Im looking to open a new activity where user can either select book room or view home from the popup menu. These should open a new activity for booking room and another activity for viewing a homes.

class MyHomeMenuItemClickListener implements PopupMenu.OnMenuItemClickListener {

public MyHomeMenuItemClickListener(){

}

@Override
public boolean onMenuItemClick(MenuItem menuItem) {
    switch (menuItem.getItemId()) {
        case R.id.bookings_page:
            Intent bookingIntent = new Intent(this, BookingPayments.class);
            return true;
        case R.id.view_homes_menu:
            return true;
        default:
    }
    return false;
}

}

the error keeps poping up under the (this, BookingsPayment.class);

NEED HELP

2 Answers

Hello!

You should also call startActivity(bookingIntent) right after you declare it. That should make it work.

Good luck!

Hi sorry its still not working. still getting the cannot resolve constructor error message for (this, BookingPayment.class); and now getting error for startActivity Cannot resolve method.

Intent bookingIntent = new Intent(mContext, BookingPayments.class); mContext.startActivity(bookingIntent);

This worked for me