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 7401641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:31:37+00:00 2026-05-29T04:31:37+00:00

I have two layouts: main.xml and journal.xml When I click on a button in

  • 0

I have two layouts: main.xml and journal.xml
When I click on a button in the main.xml layout, the journal.xml layout will be opened.

The problem is that i would like to create a back button which will re-open the main.xml layout.
When I try to do:

ImageButton buttonHome = (ImageButton)findViewById(R.id.image);

The image is not found because she is not in my main.xml

Could you please help me.

Thanks

Here is the code:

public class MDPI_1Activity extends Activity 
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.journal);
        ImageButton buttonJournal = (ImageButton)findViewById(R.id.imageButton1); //Journal
        ImageButton buttonHome = (ImageButton)findViewById(R.id.image); //Journal


        buttonJournal.setOnClickListener(new Button.OnClickListener() 
        {

            public void onClick(View v) 
            {

                setContentView(R.layout.journal);
            }
        });


        buttonHome.setOnClickListener(new Button.OnClickListener() 
        {

            public void onClick(View v) 
            {

                setContentView(R.layout.main);
            }
        });

    }

}

The “imageButton1” is in my main.xml file and works good but the “image” is in my second xml file named “journal” and does not exist in the R file.

  • 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-29T04:31:40+00:00Added an answer on May 29, 2026 at 4:31 am

    EDIT: I don’t know if this will work.. but you can set the onClick parameter on your layout (XML) like this:

    //Activity
    public class MDPI_1Activity extends Activity 
    {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.journal);
    
        }
    
    
        public void goJournal(View v)
        {
    
            setContentView(R.layout.journal);
        }
    
    
        public void goHome(View v)
        {
    
            setContentView(R.layout.main);
        }
    
    }
    
    //BUTTON IN HOME LAYOUT
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Journal"
        android:onClick="goJournal" />
    
    //BUTTON IN JOURNAL LAYOUT
    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Home"
        android:onClick="goHome" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In main.xml, I have a table layout that it has two buttons in the
I have two button and want to change layout content on click button on
I have an Activity with two layouts, both implemented in R.layout.main. The first one
fI have created two layout files. First one is main.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout
I have two layouts xml and can't get the second layout to work correctly.
I have noticed in my main.xml layout, I'm creating a Tab Layout, that the
I have two main.xml files in layout-land and layout-port folders and when the orientation
I'm very very new on Android development. I have designed two xmls layouts (main.xml
I have a xml -layout file main with two textviews A/B and a view
I have some NSViews that I'm putting in one of two layouts depending on

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.