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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:49:57+00:00 2026-05-25T19:49:57+00:00

How would I implement a Buttonlistener for a second layout which is still be

  • 0

How would I implement a Buttonlistener for a second layout which is still be called in the main Acitivity?
I already tried it by a named Button listener and via an anonymous. But still get nullpointer Exceptions.

Code:

back = (Button) findViewById(R.id.backToMain);
 if(back != null)
    back.setOnClickListener( new View.OnClickListener() {
                public void onClick(View view) {
                    setLayout(R.layout.main);
                }
            });

Layout.xml

<Button android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:id="@+id/backToMain"
        android:text="Zurück">
    </Button>
  • 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-25T19:49:57+00:00Added an answer on May 25, 2026 at 7:49 pm

    Try this

    Change the button attr tag

    <Button android:layout_width="fill_parent" 
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:id="@+id/backToMain"
            android:text="Zurück"
            android:onClick="goBack">
        </Button>
    

    In your activity create a method

    public void goBack(View v) {
    //Write code here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On which technological basis would you implement a multimedia app, which has to meet
Recently I've been thinking about finite state machines (FSMs), and how I would implement
How would you implement a system with the following objectives: Manage authentication, authorization for
How would I implement a binary search using just an array?
When would I implement IDispose on a class as opposed to a destructor? I
How would you implement a Plugin-system for your Java application? Is it possible to
How would you implement a capacity-limited, generic MruList in C# or Java? I want
How would you implement paging in a LINQ query? Actually for the time being,
Possible Duplicates: How would I implement stackoverflow’s hovering dialogs? i want a small box
What is the dispatcher pattern and how would I implement it in code? I

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.