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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T22:28:51+00:00 2026-06-05T22:28:51+00:00

I have used multiple activities to handle mutiple views in android . I found

  • 0

I have used multiple activities to handle mutiple views in android . I found that some where in the blog but I’m lost inside it.

I’m not able to switch between 2 views , my code is as follows:

main file

public class MultiViewActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Button next = (Button) findViewById(R.id.button1);  
        next.setOnClickListener(new View.OnClickListener() {  
         public void onClick(View view) {  
           Intent myIntent = new Intent(view.getContext(), MultiViews2.class);  
           startActivityForResult(myIntent, 0);  
         }  
       });
    }
}

xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button android:text="View 2"  
          android:id="@+id/button1"  
         android:layout_width="fill_parent"  
          android:layout_height="wrap_content">  
      </Button>  

</LinearLayout>

another activity:

 public class MultiViews2 extends Activity {  
    /** Called when the activity is first created. */  
    @Override  
    public void onCreate(Bundle savedInstanceState) {  
      super.onCreate(savedInstanceState);  
      setContentView(R.layout.main2);  
      Button next = (Button) findViewById(R.id.button1);  
            next.setOnClickListener(new View.OnClickListener() {  
             public void onClick(View view) {  
               Intent myIntent = new Intent(view.getContext(), MultiViewActivity.class);  
               startActivityForResult(myIntent, 0);  
             }  
           });  
    }  
  }  

xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button android:text="View 1"  
          android:id="@+id/button2"  
         android:layout_width="fill_parent"  
          android:layout_height="wrap_content">  
      </Button>  

</LinearLayout>

manifest :

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.multiview.org"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".MultiViewActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MultiViews2"></activity>
    </application>

</manifest>

whenever I click on button2 it shows me error the application has stopped unexpectedly.
Anything I missed above. I’m very new to android programming.

  • 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-06-05T22:28:54+00:00Added an answer on June 5, 2026 at 10:28 pm

    Problem in Below line in MultiViews2 Class

    Button next = (Button) findViewById(R.id.button2); 
    

    Instead Of

    Button next = (Button) findViewById(R.id.button1);  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I simply have 2 tabs and used Experience - Multiple Android Activities in a
I simply have 2 tabs and used Experience - Multiple Android Activities in a
I have used Experience - Multiple Android Activities in a TabActivity to implement tab.
I have various Java Swing applications that are used by multiple users. My deployment
I'm starting an Android app which will have multiple Activities. It will be using
I have a simple HTML template that's used multiple times across the document. It's
I have a set of classes that are used multiple times on a page
I have created a compound control that I am reusing in multiple activities. This
I have a datamodel used by multiple application that I now needs to be
I have used the tutorial on here but for some reason it didn't work.

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.