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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:33:26+00:00 2026-06-17T18:33:26+00:00

Need some help with switching from activity to activity in android development. I am

  • 0

Need some help with switching from activity to activity in android development. I am trying to go from my MainActivity activity to my MainMenu activity. I implemented a onclicklistener to do the job. When i run the app on the simulator it runs fine however when i click the button implemented with the onclicklistener it does nothing.

package com.example.bmiworking;

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






            public class MainActivity extends Activity implements OnClickListener{
            /** Called when the activity is first created. */
            Button btn;
            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_main);
                 btn = (Button)findViewById(R.id.homeClickHandler);
            }
            public void onClick(View v){
                if(v.getId() == R.id.homeClickHandler){
                startActivity(new Intent(this,MainMenu.class));
                }
            }


            public void calculateClickHandler(View view) {
             // make sure we handle the click of the calculator button

             if (view.getId() == R.id.calculateButton) {

              // get the references to the widgets
              EditText weightText = (EditText)findViewById(R.id.weightText);
              EditText heightText = (EditText)findViewById(R.id.heightText);
              TextView resultText = (TextView)findViewById(R.id.resultLabel);

              // get the users values from the widget references

              float weight = Float.parseFloat(weightText.getText().toString());
              float height = Float.parseFloat(heightText.getText().toString());

              // calculate the bmi value

              float bmiValue = calculateBMI(weight, height);

              // interpret the meaning of the bmi value
              String bmiInterpretation = interpretBMI(bmiValue);

              // now set the value in the result text

              resultText.setText(bmiValue + "-" + bmiInterpretation);
             }
            }

            // the formula to calculate the BMI index

            // check for http://en.wikipedia.org/wiki/Body_mass_index
            private float calculateBMI (float weight, float height) {

             return (float) (weight * 4.88 / (height * height));
            }


            // interpret what BMI means
            private String interpretBMI(float bmiValue) {

             if (bmiValue < 16) {
              return "Severely Underweight - See Weight Gain";
             } else if (bmiValue < 18.5) {

              return "Underweight - See Weight Gain";
             } else if (bmiValue < 25) {

              return "Normal - No Recomendations";
             } else if (bmiValue < 30) {

              return "Overweight - See Weight Loss";
             } else {
              return "Obese - See Weight Loss";
             }

            }


            @Override
            public void onClick(DialogInterface arg0, int arg1) {
                // TODO Auto-generated method stub

            }
        }



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

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:text="BMI Calculator"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <EditText
            android:id="@+id/weightText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView2"
            android:layout_centerHorizontal="true"
            android:ems="10"
            android:inputType="numberDecimal" >

            <requestFocus />
        </EditText>

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView1"
            android:layout_centerHorizontal="true"
            android:text="@string/weightLabel"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/weightText"
            android:layout_centerHorizontal="true"
            android:text="@string/heightLabel"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <EditText
            android:id="@+id/heightText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignLeft="@+id/weightText"
            android:layout_below="@+id/textView3"
            android:ems="10"
            android:inputType="numberDecimal" />

        <Button
            android:id="@+id/calculateButton"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/heightText"
            android:layout_centerHorizontal="true"
            android:onClick="calculateClickHandler"
            android:text="@string/calculateButton" />

        <TextView
            android:id="@+id/resultLabel"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_below="@+id/calculateButton"
            android:layout_marginLeft="30dp"
            android:layout_marginTop="15dp"
            android:text="@string/emptyString"
            android:textAppearance="?android:attr/textAppearanceLarge" />

        <Button
            android:id="@+id/homeClickHandler"
            style="?android:attr/buttonStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:text="@string/homeButton" />

    </RelativeLayout>

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

        <uses-sdk
            android:minSdkVersion="8"
            android:targetSdkVersion="17" />

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.bmiworking.MainActivity"
                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="com.example.bmiworking.MainMenu"
                android:label="@string/app_name" >
                </activity>
        </application>

    </manifest>
  • 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-17T18:33:27+00:00Added an answer on June 17, 2026 at 6:33 pm

    You’re importing the wrong OnClickListener, so remove that import and also remove the DialogInterface onClick method.

    import android.view.View.OnClickListener;
    

    Below “btn = (Button)findViewById(R.id.homeClickHandler);” and:

    btn.setOnClickListener(this);
    

    Complete:

    package com.example.bmiworking;
    
    import android.app.Activity;
    import android.content.DialogInterface;
    import android.view.View.OnClickListener;
    import android.content.Intent;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.TextView;
    
    public class MainActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */
    Button btn;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        btn = (Button) findViewById(R.id.homeClickHandler);
        btn.setOnClickListener(this);
    }
    
        @Override
    public void onClick(View v) {
        if (v.getId() == R.id.homeClickHandler) {
            startActivity(new Intent(this, MainMenu.class));
        }
    }
    
    public void calculateClickHandler(View view) {
        // make sure we handle the click of the calculator button
    
        if (view.getId() == R.id.calculateButton) {
    
            // get the references to the widgets
            EditText weightText = (EditText) findViewById(R.id.weightText);
            EditText heightText = (EditText) findViewById(R.id.heightText);
            TextView resultText = (TextView) findViewById(R.id.resultLabel);
    
            // get the users values from the widget references
    
            float weight = Float.parseFloat(weightText.getText().toString());
            float height = Float.parseFloat(heightText.getText().toString());
    
            // calculate the bmi value
    
            float bmiValue = calculateBMI(weight, height);
    
            // interpret the meaning of the bmi value
            String bmiInterpretation = interpretBMI(bmiValue);
    
            // now set the value in the result text
    
            resultText.setText(bmiValue + "-" + bmiInterpretation);
        }
    }
    
    // the formula to calculate the BMI index
    
    // check for http://en.wikipedia.org/wiki/Body_mass_index
    private float calculateBMI(float weight, float height) {
    
        return (float) (weight * 4.88 / (height * height));
    }
    
    // interpret what BMI means
    private String interpretBMI(float bmiValue) {
    
        if (bmiValue < 16) {
            return "Severely Underweight - See Weight Gain";
        } else if (bmiValue < 18.5) {
    
            return "Underweight - See Weight Gain";
        } else if (bmiValue < 25) {
    
            return "Normal - No Recomendations";
        } else if (bmiValue < 30) {
    
            return "Overweight - See Weight Loss";
        } else {
            return "Obese - See Weight Loss";
        }
    
    }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help with Activerecord Querying in a has_many :through association. Model: Job class
Need some help with this problem in implementing with XSLT, I had already implemented
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
I need some help. In my android app I have a ViewFlipper that contains
I'm not so good at JS and I need some help I'm trying to
need some help! I'm trying to write some code in objective-c that requires part-of-speech
Need some help with regex matching please. I'm trying to match a double quoted
Need some help designing a bash script for grepping IP addresses from auth.log and
need some help to clarify the concept. $sql = 'SELECT * FROM tbl_post LIMIT
need some help... I need to protect all the FOLDERS in a DIRECTORY from

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.