0

There is a small Problem in the app that i developed ( BMI Calculator ). Everything works well the app works well and good when user is entering the details or any pop up message and toast are well defined and works well. the main problem arise when the bottom sheet which consist of results POP-UP and nothing shows up there its just the default text view hints showing and i dont know what's the problem behind this please help me out to solve the Problem.

PLEASE NOT THAT I AM NOT GIVING ENTIRE CODE I AM JUST PROVISING THE NESSARY CODE IGNORE ANY SYNTAX ERRORS


**THIS IS THE base bmi.java FILE**

package com.suryakalyan;
public class Bmi extends AppCompatActivity {
    private double bmi;
    double weight;
    EditText edtgender, edtage, edtheight, edtweight, edtheightFeet, edtheightInches;
    TextView txtbmi_category, txtbmi_score, txtbmi_suggestion, edtdecimal;
    Button btnsubmit, recalculate;
   @Override
    protected void onCreate( Bundle savedInstanceState ) {
        super.onCreate( savedInstanceState );
        setContentView( R.layout.layout );
        
        edtgender = findViewById( R.id.gender );
        edtheightFeet = findViewById( R.id.height_feet );
        edtheightInches = findViewById( R.id.height_inches );
        edtage = findViewById( R.id.age );
        edtheight = findViewById( R.id.height );
        edtweight = findViewById( R.id.weight );
        edtdecimal = findViewById( R.id.decimal );
        btnsubmit = findViewById( R.id.submit );
        unitHeightSpinner = findViewById( R.id.unit_height_spinner );
        unitWeightSpinner = findViewById( R.id.unit_weight_spinner );
        
        
        View bottomSheetView = getLayoutInflater().inflate( R.layout.fragment_bottom_sheet_results, null );
        txtbmi_score = bottomSheetView.findViewById( R.id.bmi_score );
        txtbmi_category = bottomSheetView.findViewById( R.id.bmi_category );
        txtbmi_suggestion = bottomSheetView.findViewById( R.id.bmi_subcategory_suggestion );
        recalculate = bottomSheetView.findViewById( R.id.recalculate );
        
        
        edtgender.setOnClickListener( new View.OnClickListener() {
            @Override
            public void onClick( View v ) {
                PopupMenu popupMenu = new PopupMenu( Bmi.this, edtgender );
                popupMenu.getMenuInflater().inflate( R.menu.menu, popupMenu.getMenu() );
                popupMenu.setOnMenuItemClickListener( new PopupMenu.OnMenuItemClickListener() {
                    @Override
                    public boolean onMenuItemClick( MenuItem item ) {
                        // Handle the selected gender option here
                        String selectedGender = item.getTitle().toString();
                        edtgender.setText( selectedGender );
                        return true;
                    }
                } );
                popupMenu.show();
            }
        } );
        

      `And ALL THE REMAINING CONSIDITON AND ETC FOR BMI CALCULATION IS DONE WITHOUT ERRORS AND THE BMI IS SET USING SETTEXT`
 if (bmi < 15) {
       txtbmi_category.setText( "Better Luck Next Time!" );
       txtbmi_suggestion.setText( "Better luck next time!" );
 } else if (bmi >= 15 && bmi < 17) {
         txtbmi_category.setText( "Severely underweight" );
          txtbmi_suggestion.setText( "Don't worry, you're just a few pounds away from being super skinny!" );...............remaining conditions


**NOW THIS IS THE CODE FOR THE BOTTOM SHEET JAVA CLASS NAMES AS ExampleBottomSheetDailog.java**


`
package com.suryakalyan;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.suryakalyan.bmicalcualtor.R;

public class ExampleBottomSheetDailog extends BottomSheetDialogFragment {
    
    EditText edtgender, edtage, edtheight, edtweight, edtheightFeet, edtheightInches;
   
     Button recalculate;
    
    @Nullable
    @Override
    public View onCreateView( @NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState ) {
        View v = inflater.inflate( R.layout.fragment_bottom_sheet_results, container, false );
        return v;
    }
   
}
`



**NOW THIS IS THE CODE FOR THE BOTTOM SHEET XML FILE NAMED AS fragment_bottom_sheet_results.xml**

`
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/bottomSheetView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bottomsheet_background_gradient"
    android:orientation="vertical"
    app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior"
    tools:context="com.suryakalyan.ExampleBottomSheetDailog">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="50dp"
        android:layout_height="10dp"
        android:layout_marginTop="16dp"
        android:background="@drawable/bottom_sheet_bar"
        app:layout_constraintEnd_toEndOf="@+id/result_heading"
        app:layout_constraintStart_toStartOf="@+id/result_heading"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/result_heading"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:fontFamily="sans-serif-condensed"
        android:text="Result"
        android:textColor="#FFFFFF"
        android:textSize="32sp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/imageView" />

    <TextView
        android:id="@+id/bmi_category"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:fontFamily="sans-serif-condensed"
        android:paddingStart="16dp"
        android:paddingEnd="16dp"
        android:text="Weight Category"
        android:textAlignment="center"
        android:textColor="#FFFFFF"
        android:textSize="28sp"
        android:textStyle="italic|bold"
        app:layout_constraintEnd_toEndOf="@+id/bmi_score"
        app:layout_constraintStart_toStartOf="@+id/bmi_score"
        app:layout_constraintTop_toBottomOf="@+id/bmi_score" />

    <View
        android:id="@+id/view"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginTop="10dp"
        android:background="#B3FFFFFF"
        app:layout_constraintTop_toBottomOf="@+id/result_heading" />

    <TextView
        android:id="@+id/bmi_score"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:ellipsize="none"
        android:fontFamily="sans-serif-condensed"
        android:maxLines="1"
        android:text="0.0"
        android:textAlignment="center"
        android:textColor="#FFFFFF"
        android:textSize="120dp"
        android:textStyle="bold"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/view" />

    <View
        android:id="@+id/view2"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_marginTop="24dp"
        android:background="#4DFFFFFF"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/bmi_category" />

    <TextView
        android:id="@+id/bmi_subcategory_suggestion"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="35dp"
        android:fontFamily="sans-serif-condensed"
        android:paddingStart="16dp"
        android:paddingEnd="16dp"
        android:text="Suggestion:"
        android:textAlignment="center"
        android:textColor="#CCFFFFFF"
        android:textSize="20sp"
        android:textStyle="italic|normal"
        app:layout_constraintEnd_toEndOf="@+id/view2"
        app:layout_constraintStart_toStartOf="@+id/view2"
        app:layout_constraintTop_toBottomOf="@+id/view2" />

    <androidx.appcompat.widget.AppCompatButton
        android:id="@+id/recalculate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="30dp"
        android:layout_marginBottom="45dp"
        android:background="@drawable/button_background"
        android:padding="16dp"
        android:text="Re-Calculate"
        android:textColor="#FFFFFF"
        android:textSize="20sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/bmi_subcategory_suggestion"
        app:layout_constraintVertical_bias="0.137" />

</androidx.constraintlayout.widget.ConstraintLayout>
`

**AND NOW THIS IS THE CODE FOR THE LAYOTU.XML (BASE)**
`
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/background_gradient"
    android:gravity="center_horizontal"
    tools:context="com.suryakalyan.Bmi">

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/title_background"
        android:gravity="center"
        android:padding="16dp"
        android:text="BMI Calculator"
        android:textColor="#FFFFFF"
        android:textSize="32sp"
        android:textStyle="bold"
        android:fontFamily="sans-serif-condensed" />
<androidx.core.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">
        <EditText
            android:id="@+id/gender"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Enter Your Gender"
            android:textSize="20sp"
            android:textColor="#000000"
            android:inputType="textAutoComplete"
            android:padding="8dp"
            android:textAlignment="center"
            android:layout_marginStart="32dp"
            android:layout_marginEnd="32dp"
            android:layout_marginTop="64dp"
            android:background="@drawable/edittext_gradient"
            app:layout_constraintTop_toBottomOf="@id/title"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

        <EditText
            android:id="@+id/age"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="Enter Your Age"
            android:textSize="20sp"
            android:textColor="#000"
            android:inputType="number"
            android:padding="8dp"
            android:textAlignment="center"
            android:layout_marginStart="32dp"
            android:layout_marginEnd="32dp"
            android:layout_marginTop="32dp"
            android:background="@drawable/edittext_gradient"
            app:layout_constraintTop_toBottomOf="@id/gender"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

        <LinearLayout
            android:id="@+id/heightLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center"
            android:layout_marginStart="32dp"
            android:layout_marginEnd="32dp"
            android:layout_marginTop="32dp"
            app:layout_constraintTop_toBottomOf="@id/age"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

            <EditText
                android:id="@+id/height"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:hint="Enter Your Height"
                android:textSize="20sp"
                android:textColor="#000"
                android:inputType="numberDecimal"
                android:padding="8dp"
                android:textAlignment="center"
                android:background="@drawable/edittext_gradient" />

            <EditText
                android:id="@+id/height_feet"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:hint="Feet"
                android:inputType="number"
                android:layout_weight="1"
                android:layout_marginRight="5dp"
                android:textAlignment="center"
                android:padding="8dp"
                android:textColor="#000000"
                android:textSize="20sp"
                android:background="@drawable/edittext_gradient" />

            <TextView
                android:id="@+id/decimal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="."
                android:layout_weight="0.1"
                android:textColor="#fff"
                android:textSize="20dp"
                android:textAlignment="center"
                android:textAllCaps="true"
                android:textStyle="italic|bold"
                android:layout_gravity="center"
                android:padding="1dp"/>

            <EditText
                android:id="@+id/height_inches"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:hint="Inches"
                android:inputType="numberDecimal"
                android:layout_weight="1"
                android:layout_marginLeft="5dp"
                android:textAlignment="center"
                android:padding="8dp"
                android:textColor="#000000"
                android:textSize="20sp"
                android:background="@drawable/edittext_gradient" />

            <Spinner
                android:id="@+id/unit_height_spinner"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:padding="12dp"
                android:layout_weight="0"
                android:layout_marginLeft="0dp"
                android:entries="@array/unit_height_array" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/weightLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:gravity="center"
            android:textAlignment="center"
            android:layout_marginStart="32dp"
            android:layout_marginEnd="32dp"
            android:layout_marginTop="10dp"
            app:layout_constraintTop_toBottomOf="@id/heightLayout"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent">

            <EditText
                android:id="@+id/weight"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:hint="Enter Your Weight"
                android:textSize="20sp"
                android:textColor="#000000"
                android:inputType="number"
                android:padding="8dp"
                android:textAlignment="center"
                android:background="@drawable/edittext_gradient" />

            <Spinner
                android:id="@+id/unit_weight_spinner"
                android:layout_width="100dp"
                android:layout_height="wrap_content"
                android:padding="12dp"
                android:layout_weight="0"
                android:layout_marginLeft="0dp"
                android:entries="@array/unit_weight_array" />
        </LinearLayout>


        <androidx.appcompat.widget.AppCompatButton
            android:id="@+id/submit"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="32dp"
            android:background="@drawable/button_background"
            android:padding="16dp"
            android:text="Submit"
            android:textColor="#FFFFFF"
            android:textSize="20sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@id/weightLayout" />
    </LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
`

0 Answers0