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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:50:00+00:00 2026-06-13T19:50:00+00:00

I’m new to android and I’ve just learned about activities and I decided to

  • 0

I’m new to android and I’ve just learned about activities and I decided to create a few.

and my MainActivity.java is,

public class MainActivity extends Activity {


@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Button a = (Button) findViewById(R.id.button1);
    a.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent(MainActivity.this, WidgetIntro.class));

            Button b = (Button) findViewById(R.id.button2);
            b.setOnClickListener(new OnClickListener() {

                public void onClick(View v) {
                    // TODO Auto-generated method stub
                    startActivity(new Intent(MainActivity.this, Alarm.class));

                    Button c = (Button) findViewById(R.id.button4);
                    c.setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            startActivity(new   Intent(MainActivity.this, Sms.class));

                            Button d = (Button) findViewById(R.id.button6);
                            d.setOnClickListener(new OnClickListener() {

                                public void onClick(View v) {
                                    // TODO Auto-generated method stub
                                    startActivity(new   Intent(MainActivity.this, Call.class));

                                    Button e = (Button)   findViewById(R.id.button3);
                                    e.setOnClickListener(new OnClickListener() {

                                        public void onClick(View v) {
                                            // TODO Auto-generated method stub
                                            startActivity(new Intent(MainActivity.this, Notes.class));

                                            Button f = (Button) findViewById(R.id.button5);
                                            f.setOnClickListener(new OnClickListener() {

                                                public void onClick(View v) {
                                                    // TODO Auto-generated method stub
                                                    startActivity(new Intent(MainActivity.this, Cbdata.class));

                                                }
                                            });
                                        }
                                    });

                                }
                            });

                        }
                    });
                }
            });

Though this has no error and I’ve created some text to toast for every button, when I install my application on my phone I’m able to access buttons only in the order I’ve numbered them, that is for ‘Location Widget’ button my button id is button1 so except for this button I’m able to select any other buttons and once I’ve selected this button I can only select button 2 but not any other button, why does this happen?

My activity_main.xml code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<Button
    android:id="@+id/button7"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="26dp"
    android:text="About Us" />

 <Button
    android:id="@+id/button3"
    android:layout_width="125dp"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button7"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="36dp"
    android:text="Note Remainder" />

 <Button
    android:id="@+id/button2"
    android:layout_width="125dp"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button3"
    android:layout_alignBottom="@+id/button3"
    android:layout_alignParentLeft="true"
    android:text="Alarm" />

 <Button
    android:id="@+id/button4"
    android:layout_width="125dp"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button2"
    android:layout_alignParentLeft="true"
    android:layout_marginBottom="40dp"
    android:text="SMS" />

<Button
    android:id="@+id/button6"
    android:layout_width="125dp"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/button4"
    android:layout_alignBottom="@+id/button4"
    android:layout_alignParentRight="true"
    android:text="Call" />

<Button
    android:id="@+id/button1"
    android:layout_width="125dp"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button6"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="37dp"
    android:text="Location Widget" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:text="Hello User, Welcome to Mobile location Info! You Choose from the following options :"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<Button
    android:id="@+id/button5"
    android:layout_width="125dp"
    android:layout_height="wrap_content"
    android:layout_alignBottom="@+id/button1"
    android:layout_alignParentLeft="true"
    android:text="Save my locations" />

</RelativeLayout>

        }
    });
}

}
  • 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-13T19:50:01+00:00Added an answer on June 13, 2026 at 7:50 pm

    You have defined each buttons onClick listener inside the onClick listener of the previous button. Therefore, each button after the first one only has an assigned onClick listener when you click the previous button.

    Instead, do this:

    Button a = (Button) findViewById(R.id.button1);
    a.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent(MainActivity.this, WidgetIntro.class));
        }
    });
    
    Button b = (Button) findViewById(R.id.button2);
    b.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // TODO Auto-generated method stub
                startActivity(new Intent(MainActivity.this, Alarm.class));
       }
    });
    

    A tip. In general, when you see more than about 3 levels of closing braces, like this then you know there is a problem:

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I have thousands of HTML files to process using Groovy/Java and I need to

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.