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

Andreas Robichaux
Andreas Robichaux
2,426 Points

making my own app...how do i load next activity?

I have a basic app I am trying to make that will serve as a portfolio. I have a column of buttons down the middle on my main activity, and I want them to click the button to load the data for the proper sections (copywriting, strategy, etc..)

I got the buttons all made and lined up in there looking pretty and I made a second activity called webActivity. I was going to make one for each section, web, print, copywriting, etc... but remembered I should just make one page template and then code the rest. I honestly just did this in the class but now it seems so much harder to try and do from scratch without his help!

My question is getting the button to load the next activity. my button is called webButton so do i do something like

webButton.setOnClickListener();

and honestly thats all i remember :(

1 Answer

Dan Johnson
Dan Johnson
40,532 Points

To wire up an anonymous inner class to launch an activity all you have to do is this:

webButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Intent intent = new Intent(YourCurrentActivity.this, YourTargetActivity.class);
        startActivity(intent);
    }
});
Andreas Robichaux
Andreas Robichaux
2,426 Points

Thank you very much my man, exactly what I was looking for! You guys are the best!