Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Can someone help me with my code?

  1. #1
    Junior Member
    Join Date
    Nov 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can someone help me with my code?

    Hello can someone help me i want to know how to make a button that navigates to another activity in android studio in java
    And here are some tasks i need to do

    1.3 button that navigate to 3 activitys
    2. two buttons that navigate to 2 activitys

    Thanks if you can help😊😃

    You can post this on my smal forum so i can store it better http://bit.ly/34rA0mI

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can someone help me with my code?

    Can you post your code showing what you have tried?
    Please be sure to wrap the code in code tags.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2019
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can someone help me with my code?

    package com.example.application.myapplication;

    import android.content.Intent;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;

    public class MainActivity extends AppCompatActivity {
    private Button button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    button = (Button) findViewById(R.id.button);
    button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
    openActivity2();
    }
    });
    }

    public void openActivity2() {
    Intent intent = new Intent(this, Activity2.class);
    startActivity(intent);
    }
    }


    Willl this work

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can someone help me with my code?

    Try it and see what happens.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 6
    Last Post: August 5th, 2014, 11:19 AM
  2. Replies: 3
    Last Post: April 27th, 2013, 07:19 AM
  3. Replies: 4
    Last Post: January 24th, 2013, 11:20 AM
  4. Replies: 7
    Last Post: January 24th, 2013, 10:41 AM
  5. Replies: 3
    Last Post: September 3rd, 2012, 11:36 AM