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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:22:46+00:00 2026-05-27T09:22:46+00:00

This is my code in my main java file. How would i make another

  • 0

This is my code in my main java file. How would i make another button to connect with the activity. please tell me if i am not expressing this well enough. I just need to add another button into the main java file. I already have an activity in the manifest and a class for it, i just need to put another block of code into the main java file. The id of the button is p40, the name of the xml layout is p40.xml, the class is called p40.java and the activity is called p40. This is my code at the moment:

package com.duncan.hello.world;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.duncan.hello.world.R;

public class HelloWorldActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    Button aButton;
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    aButton = (Button) this.findViewById(R.id.button1);

    aButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(HelloWorldActivity.this, OtherActivity.class);
            startActivity(i);
        }});
}
}
  • 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-27T09:22:47+00:00Added an answer on May 27, 2026 at 9:22 am

    You should do

    // This code is copied from your code as is 
    // to have a reference point as well as this is also
    // code for adding click listener to button which you
    // need to handle click and then do what you want.
    // In this case you are launching an Activity
    // Block of code you already have to use STARTS
    aButton = (Button) this.findViewById(R.id.button1);
    
    aButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(HelloWorldActivity.this, OtherActivity.class);
            startActivity(i);
        }});
    // Block of code you already have to use ENDS
    
    // This code is added for newButton which looks similar to above block
    Button newButton
    newButton = (Button) this.findViewById(R.id.button2);
    
    newButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            Intent i = new Intent(HelloWorldActivity.this, AnOtherActivity.class);
            startActivity(i);
        }});
    

    You have to add another button1 in layout/main.xml file.

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

Sidebar

Related Questions

Please consider this code: template<typename T> char (&f(T[1]))[1]; template<typename T> char (&f(...))[2]; int main()
Consider this code: int main() { int e; prn(e); return 0; } void prn(double
With C#, i use this code to list main window processes titles Process[] ProcessArray
This code compiles: private static void Main(string[] args) { bool? fred = true; if
Does this code cause a memory leak: int main(){ int * a = new
Why is this code throwing up a SIGSEGV : int main() { unsigned long
In my computer this code takes 17 seconds (1000 millions times): static void Main(string[]
Take a look at this code: public class Test { public static void main(String...
Consider this code: void res(int a,int n) { printf(%d %d, ,a,n); } void main(void)
I have this code #include <iostream> using namespace std; int main(int argc,char **argv) {

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.