Java “条件”;如果(height_spinner.getSelectedItemPosition()==1)";没有被处决 weight\u微调器=findviewbyd(R.id.weight\u微调器); ArrayAdapter\u weight=ArrayAdapter.createFromResource(这个,R.array.weight,android.R.layout.simple\u微调器\u项); adapter\u weight.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项); 重量\微调器。设置适配器(适配器\重量); 权重微调器.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){ @凌驾 未选择公共无效(AdapterView父级){ } @凌驾 已选择公共视图(AdapterView父视图、视图视图、整型位置、长id){ 开关(位置){ 案例0: 重量(kg); 重量1.设置可见性(视图已消失); 重量1.setEnabled(错误); 重量等设定启用(真); 如果(高度\u微调器.getSelectedItemPosition()==0) { 线程t=新线程(){ @凌驾 公开募捐{ 而(!isInterrupted()){ 试一试{ 睡眠(1000); runOnUiThread(新的Runnable(){ @凌驾 公开募捐{ 计数++; 字符串高度=高度\u et.getText().toString().trim(); String Weight=Weight_et.getText().toString().trim(); 字符串age=age_et.getText().toString().trim(); String gender=gender_spinner.getSelectedItem().toString().trim(); if(Height.isEmpty()){ 返回; } if(Weight.isEmpty()){ 结果_tv.setText(“”); 返回; } if(gender.isEmpty()| age.isEmpty()){ fat_tv.setText(“”); 年龄等设置错误(“请输入年龄”); 年龄等请求焦点(); 返回; } //从小部件引用获取用户值 int Age=Integer.parseInt(Age); 浮动重量=浮动。解析浮动(重量); 浮动高度=浮动。浮动(高度)/100; //计算体重指数值 浮动BMI值=计算BMI(体重、身高); DecimalFormat DecimalFormat=新的DecimalFormat(“#.#”); 最终字符串舍入值=十进制格式(bmivalue); //计算理想重量 浮动百分比=0.0f; 字符串四舍五入\u fatpercent=null; if(性别平等(“男性”)和年龄=18){ fatpercent=成人fatPercentage(BMI值,年龄,1); 四舍五入=十进制格式(fatpercent); } 否则,如果(性别相等(“女性”)和年龄=18){ fatpercent=成人fatPercentage(BMI值,年龄,0); 四舍五入=十进制格式(fatpercent); } //定义bmi值的含义 最终字符串BMI解释=解释BMI(BMI值); 如果(bmiValue=16&&bmiValue 17&&bmiValue=18.5&&bmiValue 25&&bmiValue=30&&bmiValue=35&&bmiValue=30&&bmiValue=35&&bmiValue

Java “条件”;如果(height_spinner.getSelectedItemPosition()==1)";没有被处决 weight\u微调器=findviewbyd(R.id.weight\u微调器); ArrayAdapter\u weight=ArrayAdapter.createFromResource(这个,R.array.weight,android.R.layout.simple\u微调器\u项); adapter\u weight.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项); 重量\微调器。设置适配器(适配器\重量); 权重微调器.setOnItemSelectedListener(新的AdapterView.OnItemSelectedListener(){ @凌驾 未选择公共无效(AdapterView父级){ } @凌驾 已选择公共视图(AdapterView父视图、视图视图、整型位置、长id){ 开关(位置){ 案例0: 重量(kg); 重量1.设置可见性(视图已消失); 重量1.setEnabled(错误); 重量等设定启用(真); 如果(高度\u微调器.getSelectedItemPosition()==0) { 线程t=新线程(){ @凌驾 公开募捐{ 而(!isInterrupted()){ 试一试{ 睡眠(1000); runOnUiThread(新的Runnable(){ @凌驾 公开募捐{ 计数++; 字符串高度=高度\u et.getText().toString().trim(); String Weight=Weight_et.getText().toString().trim(); 字符串age=age_et.getText().toString().trim(); String gender=gender_spinner.getSelectedItem().toString().trim(); if(Height.isEmpty()){ 返回; } if(Weight.isEmpty()){ 结果_tv.setText(“”); 返回; } if(gender.isEmpty()| age.isEmpty()){ fat_tv.setText(“”); 年龄等设置错误(“请输入年龄”); 年龄等请求焦点(); 返回; } //从小部件引用获取用户值 int Age=Integer.parseInt(Age); 浮动重量=浮动。解析浮动(重量); 浮动高度=浮动。浮动(高度)/100; //计算体重指数值 浮动BMI值=计算BMI(体重、身高); DecimalFormat DecimalFormat=新的DecimalFormat(“#.#”); 最终字符串舍入值=十进制格式(bmivalue); //计算理想重量 浮动百分比=0.0f; 字符串四舍五入\u fatpercent=null; if(性别平等(“男性”)和年龄=18){ fatpercent=成人fatPercentage(BMI值,年龄,1); 四舍五入=十进制格式(fatpercent); } 否则,如果(性别相等(“女性”)和年龄=18){ fatpercent=成人fatPercentage(BMI值,年龄,0); 四舍五入=十进制格式(fatpercent); } //定义bmi值的含义 最终字符串BMI解释=解释BMI(BMI值); 如果(bmiValue=16&&bmiValue 17&&bmiValue=18.5&&bmiValue 25&&bmiValue=30&&bmiValue=35&&bmiValue=30&&bmiValue=35&&bmiValue,java,android,Java,Android,,这是因为当您处于位置0(也称为案例0)时: 代码:height\u spinner.getSelectedItemPosition()等于0(在位置1,它将等于1,依此类推) 因此,条件:height\u spinner.getSelectedItemPosition()==1将永远不会在案例0中调用。请不要转储所有代码。创建一个并显示您在解决该问题时的尝试。否则(height\u spinner.getSelectedItemPosition()==1)。在调试代码first@achAmh密

,这是因为当您处于位置0(也称为案例0)时:

代码:
height\u spinner.getSelectedItemPosition()
等于0(在位置1,它将等于1,依此类推)


因此,条件:
height\u spinner.getSelectedItemPosition()==1
将永远不会在案例0中调用。请不要转储所有代码。创建一个并显示您在解决该问题时的尝试。
否则(height\u spinner.getSelectedItemPosition()==1)
。在调试代码first@achAmh密码中的缩写不,请查看it@IntelliJAmiya如果要在以下条件下执行代码,则代码无效:height\u spinner.getSelectedItemPosition()==1
weight_spinner= findViewById(R.id.weight_spinner);
ArrayAdapter<CharSequence> adapter_weight = ArrayAdapter.createFromResource(this,R.array.Weight,android.R.layout.simple_spinner_item);
        adapter_weight.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        weight_spinner.setAdapter(adapter_weight);


        weight_spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }

            @Override
            public void onItemSelected(AdapterView parent, View view, int position, long id) {
                switch (position){
                    case 0:
                        weight_et.setHint("Weight(kg)");
                        weight_et1.setVisibility(View.GONE);
                        weight_et1.setEnabled(false);
                        weight_et.setEnabled(true);

                        if (height_spinner.getSelectedItemPosition()==0)
                        {

                            Thread t = new Thread(){
                                @Override
                                public void run() {
                                    while (!isInterrupted()){
                                        try {
                                            Thread.sleep(1000);
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    count++;
                                                    String Height = height_et.getText().toString().trim();
                                                    String Weight = weight_et.getText().toString().trim();

                                                    String age = age_et.getText().toString().trim();
                                                    String gender =  gender_spinner.getSelectedItem().toString().trim();

                                                    if(Height.isEmpty()){
                                                        return;
                                                    }

                                                    if(Weight.isEmpty()){
                                                        result_tv.setText("");
                                                        return;
                                                    }


                                                    if (gender.isEmpty() || age.isEmpty()){
                                                        fat_tv.setText("");
                                                        age_et.setError("Please Enter Age");
                                                        age_et.requestFocus();
                                                        return;
                                                    }



//Get the user values from the widget reference
                                                    int Age = Integer.parseInt(age);
                                                    float weight = Float.parseFloat(Weight);
                                                    float height = Float.parseFloat(Height)/100;

//Calculate BMI value
                                                    float bmiValue = calculateBMI(weight, height);
                                                    DecimalFormat decimalFormat = new DecimalFormat("#.#");
                                                    final String rounded_bmivalue= decimalFormat.format(bmiValue);
//Calculate Ideal Weight

                                                    float fatpercent = 0.0f;
                                                    String rounded_fatpercent = null;
                                                    if (gender.equals("Male") && Age <18){
                                                        fatpercent = Childfatpercentage(bmiValue,Age,1);
                                                        rounded_fatpercent = decimalFormat.format(fatpercent);
                                                    }
                                                    else if (gender.equals("Male") && Age >=18){
                                                        fatpercent = Adultfatpercentage(bmiValue,Age,1);
                                                        rounded_fatpercent = decimalFormat.format(fatpercent);
                                                    }
                                                    else if (gender.equals("Female") && Age <18){
                                                       fatpercent = Childfatpercentage(bmiValue,Age,0);
                                                        rounded_fatpercent = decimalFormat.format(fatpercent);
                                                    }
                                                    else if (gender.equals("Female") && Age >=18){
                                                       fatpercent = Adultfatpercentage(bmiValue,Age,0);
                                                        rounded_fatpercent = decimalFormat.format(fatpercent);
                                                    }


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

                                                    if (bmiValue<16) {
                                                        result_tv.setTextColor(Color.parseColor("#FF0000"));
                                                        fat_tv.setTextColor(Color.parseColor("#FF0000"));
                                                    }
                                                    else if (bmiValue >=16 && bmiValue<=17){
                                                        result_tv.setTextColor(Color.parseColor("#FF6347"));
                                                        fat_tv.setTextColor(Color.parseColor("#FF0000"));
                                                    }
                                                    else if (bmiValue>17 && bmiValue <18.5) {
                                                        result_tv.setTextColor(Color.parseColor("#9ACD32"));
                                                        fat_tv.setTextColor(Color.parseColor("#FF0000"));
                                                    }
                                                    else if (bmiValue>=18.5 && bmiValue <= 25) {
                                                        result_tv.setTextColor(Color.parseColor("#008000"));
                                                        fat_tv.setTextColor(Color.parseColor("#FF0000"));
                                                    }
                                                    else if ( bmiValue > 25 && bmiValue < 30) {
                                                        result_tv.setTextColor(Color.parseColor("#9ACD32"));
                                                        fat_tv.setTextColor(Color.parseColor("#FF0000"));
                                                    }
                                                    else if (bmiValue >= 30 && bmiValue <35){
                                                        result_tv.setTextColor(Color.parseColor("#FF4500"));
                                                        fat_tv.setTextColor(Color.parseColor("#FF0000"));
                                                    }
                                                    else if (bmiValue >= 35 && bmiValue <40){
                                                        result_tv.setTextColor(Color.parseColor("#FF6347"));
                                                        fat_tv.setTextColor(Color.parseColor("#FF0000"));
                                                    }
                                                    else {
                                                        result_tv.setTextColor(Color.parseColor("#FF0000"));
                                                        fat_tv.setTextColor(Color.parseColor("#FF0000"));
                                                    }
                                                    result_tv.setText(rounded_bmivalue + " - " + bmiInterpretation);
                                                    fat_tv.setText("Fat : "+rounded_fatpercent+" %");
                                                }
                                            });
                                        } catch (InterruptedException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }
                            };
                            t.start();

                        }

                        if (height_spinner.getSelectedItemPosition()==1){


                            Thread t = new Thread(){
                                @Override
                                public void run() {
                                    while (!isInterrupted()){
                                        try {
                                            Thread.sleep(1000);
                                            runOnUiThread(new Runnable() {
                                                @Override
                                                public void run() {
                                                    count++;
                                                    String Height = height_et.getText().toString().trim();
                                                    String Weight = weight_et.getText().toString().trim();
                                                    String Height1 = height_et1.getText().toString().trim();

                                                    if(Height.isEmpty()){
                                                        return;
                                                    }

                                                    if(Weight.isEmpty()){
                                                        result_tv.setText("");
                                                        return;
                                                    }

                                                    if (Height1.isEmpty()){
                                                        return;
                                                    }

                                                    float weight = Float.parseFloat(Weight);
                                                    float feet = Float.parseFloat(Height);
                                                    float inches = Float.parseFloat(Height1);
                                                    float height = convertftandin(feet,inches)/100;

//Calculate BMI value
                                                    float bmiValue = calculateBMI(weight,height);
                                                    DecimalFormat decimalFormat = new DecimalFormat("#.#");
                                                    String rounded_bmivalue= decimalFormat.format(bmiValue);
//Calculate Ideal Weight
                                                    String bmiInterpretation = interpretBMI(bmiValue);

                                                    if (bmiValue<16) {
                                                        result_tv.setTextColor(Color.parseColor("#FF0000"));
                                                    }
                                                    else if (bmiValue >=16 && bmiValue<=17){
                                                        result_tv.setTextColor(Color.parseColor("#FF6347"));
                                                    }
                                                    else if (bmiValue>17 && bmiValue <18.5) {
                                                        result_tv.setTextColor(Color.parseColor("#9ACD32"));
                                                    }
                                                    else if (bmiValue>=18.5 && bmiValue <= 25) {
                                                        result_tv.setTextColor(Color.parseColor("#008000"));
                                                    }
                                                    else if ( bmiValue > 25 && bmiValue < 30) {
                                                        result_tv.setTextColor(Color.parseColor("#9ACD32"));
                                                    }
                                                    else if (bmiValue >= 30 && bmiValue <35){
                                                        result_tv.setTextColor(Color.parseColor("#FF4500"));
                                                    }
                                                    else if (bmiValue >= 35 && bmiValue <40){
                                                        result_tv.setTextColor(Color.parseColor("#FF6347"));
                                                    }
                                                    else {
                                                        result_tv.setTextColor(Color.parseColor("#FF0000"));
                                                    }

                                                    result_tv.setText(rounded_bmivalue + " - " + bmiInterpretation);

                                                }
                                            });
                                        } catch (InterruptedException e) {
                                            e.printStackTrace();
                                        }
                                    }
                                }
                            };
                            t.start();


                        }

                        break;
                    case 1:
                        weight_et.setHint("Weight(lb)");
                        weight_et1.setVisibility(View.GONE);break;
                    case 2:
                        weight_et.setHint("st");
                        weight_et1.setVisibility(View.VISIBLE);
                        weight_et1.setHint("lb");break;

                }

            }

        });






}

 @Override
        public void onItemSelected(AdapterView parent, View view, int position, long id) {
            switch (position){
                case 0:
                    weight_et.setHint("Weight(kg)");
                    weight_et1.setVisibility(View.GONE);
                    weight_et1.setEnabled(false);
                    weight_et.setEnabled(true);

                    if (height_spinner.getSelectedItemPosition()==0) {...}