Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7564523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:55:47+00:00 2026-05-30T13:55:47+00:00

How to switch layouts? First, I have a class Main where is onCreate (

  • 0

How to switch layouts? First, I have a class Main where is onCreate (setContentView(R.layout.main);) and then I call, another class with command:

setContentView(secondClass);

In this class, I draw with Canvas and this work just fine. I also create button to go back in first "class" (R.layout.main), but I don’t know how to do it.

Now my program is basic a graph shower. In first class you type your function and them second class draw it. But how to go back in first class to type another function. This "back" button or arrow witch every Android phone have, send me out of program not back on insert part.

In secondClass I can’t create onCreate method, but I also tried the following and they didn’t work:

Intent abc = new Intent("bla.bla.bla.FIRSTCLASS");

startActivity(abc);

and

Intent abc = new Intent(SecondClass.this,FirstClass.class);

startActivity(greNaPrvoOkno);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:55:48+00:00Added an answer on May 30, 2026 at 1:55 pm

    If you want to use a custom view (as I understood, you are extending the View class), you can do it in the following way;

    Consider you are showing the second class from your Main activity like this;

    setContentView(new SecondClass(getApplicationContext(), MainActivity.this));
    

    And you Second class is this (suppose);

    // I am using onClickListener to go back to main view. You do whatever you like.
    public class SecondClass extends View implements OnClickListener {
    
        // This is needed to switch back to the parent activity
        private Activity mParentActivity = null;
    
        public SecondClass(Context context, Activity parentActivity) {
            super(context);
    
            mParentActivity = parentActivity;   
            setOnClickListener(this);
        }
    
        @Override
        public void onClick(View v) {
            // Set the Main view back here.
            mParentActivity.setContentView(R.layout.main);
        }
    
    }
    

    Disclaimer: This code will do what you have asked for, but may cause other problems.

    As advised by @Mudassir, you should use two different activities for two screens. It will give you better control, and your code will be easy to understand and maintain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the first activity that call a dialog from second activity with this
If I switch on the generating of debug info with Javac then the class
I have a private onClickListener class with a switch statement for everybutton Some buttons,
I have defined an ArrayList in my main class where I am loading data
I have two layouts within a fragment that I switch back and forth between
I have work that needs to be done in this order: In main activity:
I want to switch between vertical and horizontal table layout for same data. Although
Switch statements are typically faster than equivalent if-else-if statements (as e.g. descibed in this
I can switch between windows with C-x o, but if I have opened multiple
How do i have an AutoComplete selection based on alphabetic instead of fixed switch

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.