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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:43:01+00:00 2026-06-08T07:43:01+00:00

I’m new to coding and a little iffy with my knowledge so forgive me

  • 0

I’m new to coding and a little iffy with my knowledge so forgive me if I’ve overlooked something simple, but I’ve been searching for 2 hours for an answer.

One of my classes is going to allow a user to input their height and weight, and return the BMI (Body Mass Index) for them. The problem is once they click on the button that performs the calculation and displays it in a TextView, nothing happens. The only error I see from LogCat is getCursorCapsMode on inactive InputConnection. This error only shows when I use the next button on the softkeyboard to move between EditText fields, so I don’t believe this is related, as there is still no result when I manually move between fields and don’t get this error. Feel free to assist with this issue too though, if you have any info.

This is duplicate code from a BMI android developing tutorial, word for word except for the id’s of the items, but the tutorial works perfectly when loaded into the emulator. My code is as follows:

public class FuncConverter extends DashMenuActivity {


@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView (R.layout.dash_converter7);

    Spinner converter_spinner = (Spinner) findViewById(R.id.converter_spinner);
    ArrayAdapter<CharSequence> converter_adapter = ArrayAdapter.createFromResource(
            this, R.array.converter_array, android.R.layout.simple_spinner_item);

    converter_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        converter_spinner.setAdapter(converter_adapter);

}


public void calcClick (View view) {

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

        EditText weight_edit = (EditText) findViewById(R.id.weight_edit);
        EditText height_edit = (EditText) findViewById(R.id.height_edit);
        TextView bmi_text = (TextView) findViewById(R.id.bmi_text);

        float weight = Float.parseFloat(weight_edit.getText().toString());
        float height = Float.parseFloat(height_edit.getText().toString());

        float bmiValue = calculateBMI (weight, height);
        String bmiCalc = interpretBMI (bmiValue);

        bmi_text.setText(bmiValue + " - " + bmiCalc); 

    }

}


private float calculateBMI (float weight, float height) {
    return (float) (weight / (height * height));
}

private String interpretBMI(float bmiValue) {
    if (bmiValue < 16) {
        return "Severley Underweight";
    } else if (bmiValue < 18.5) {
        return "Underweight";
    } else if (bmiValue < 25) {
        return "Healthy weight";
    } else if (bmiValue < 30) {
        return "Overweight";
    } else {
        return "Obese";
    }
}}  
  • 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-08T07:43:03+00:00Added an answer on June 8, 2026 at 7:43 am

    Its really hard for me to answer definitively because I am not sure how you are triggering the click to calculate the stuff. But from what i can tell calcClick(View) is defined as onClick=calcClick in your xml. If this is true then you are getting the information the wrong way.

    public class FuncConverter extends DashMenuActivity {
    EditText weight_edit;
    EditText height_edit;
    TextView bmi_text;
    
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView (R.layout.dash_converter7);
    
        Spinner converter_spinner = (Spinner) findViewById(R.id.converter_spinner);
        ArrayAdapter<CharSequence> converter_adapter = ArrayAdapter.createFromResource(
            this, R.array.converter_array, android.R.layout.simple_spinner_item);
    
        converter_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        converter_spinner.setAdapter(converter_adapter);
    
        //Moved these bad boys here for you instead
        weight_edit = (EditText) findViewById(R.id.weight_edit);
        height_edit = (EditText) findViewById(R.id.height_edit);
        bmi_text = (TextView) findViewById(R.id.bmi_text);
    
    }
    
    
    public void calcClick (View view) {
    
    if (view.getId() == R.id.convert_btn_calc) { //dont't think you need this check to be honest
    
    
    
        float weight = Float.parseFloat(weight_edit.getText().toString());
        float height = Float.parseFloat(height_edit.getText().toString());
    
        float bmiValue = calculateBMI (weight, height);
        String bmiCalc = interpretBMI (bmiValue);
    
        bmi_text.setText(bmiValue + " - " + bmiCalc); 
    
        }
    
    }
    

    What I did there was just move the EditText and TextView as globals so then you have access to it in calcClick(View). If I am right , the reason it wasn’t working is because you don’t have access to the EditText and TextView views from the xml outside of onCreate(), at least in your case. What that View argument is that is getting passed is actually the button or whatever is triggering the event. Hopefully that makes sense. So View view isn’t the document root but rather (Button)view or again, whatever you are clicking to trigger this.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
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 want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
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 have a French site that I want to parse, but am running into

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.