gpt4 book ai didi

java - SetText 显示文本不显示

转载 作者:行者123 更新时间:2023-12-02 06:06:38 27 4
gpt4 key购买 nike

我正在 Android 上开发一个小应用程序,但第二行在 SetText 上显示错误imcInterpretation 包含文本值。

imcVlaue 正在工作,但 imcInterpreter 不工作!请帮忙

    package com.example.calculadorimc;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;

public class MainActivity extends Activity {
private RadioGroup rgsexo;
EditText editPeso;
EditText editAltura;
TextView imcView;
TextView imcInterpreter;
SeekBar alterarAltura;
SeekBar alterarPeso;
ImageView imagem;

@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

editPeso = (EditText)findViewById(R.id.editPeso);
editAltura = (EditText)findViewById(R.id.editAltura);
imcView = (TextView)findViewById(R.id.imcView);
imcInterpreter = (TextView)findViewById(R.id.imcInterpreter);
alterarAltura = (SeekBar)findViewById(R.id.alterarAltura);
alterarPeso = (SeekBar)findViewById(R.id.alterarPeso);
imagem = (ImageView)findViewById(R.id.imageBody);
alterarAltura.setOnSeekBarChangeListener(alteraralturaListener);
alterarPeso.setOnSeekBarChangeListener(alterarpesoListener);


}

private OnSeekBarChangeListener alteraralturaListener = new OnSeekBarChangeListener() {

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub

double setAltura = (alterarAltura.getProgress()) * .01d;
// mostra na caixa o valor novo
editAltura.setText(String.format("%.02f", setAltura).replace(',', '.'));
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}
};
private OnSeekBarChangeListener alterarpesoListener = new OnSeekBarChangeListener() {

@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
// Calcula o novo valor do TIP

int setPeso = (alterarPeso.getProgress());
// mostra na caixa o valor novo
editPeso.setText(String.valueOf(setPeso));
}

@Override
public void onStopTrackingTouch(SeekBar seekBar) {

}

@Override
public void onStartTrackingTouch(SeekBar seekBar) {

}
};
public void calculateClickHandler(View view) {

// make sure we handle the click of the calculator button

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

// get the users values from the widget references

float peso = Float.parseFloat(editPeso.getText().toString());
float altura = Float.parseFloat(editAltura.getText().toString());

// calculate the bmi value

float imcValue = calcularIMC(peso, altura);

TextView imcInterpreter = (TextView)findViewById(R.id.imcInterpreter);

// interpret the meaning of the bmi value
String imcInterpretation = interpretIMC(imcValue);

// now set the value in the result text


imcView.setText(String.format("%.02f", imcValue).replace(',', '.'));
imcInterpreter.SetText(imcInterpretation);

}
}
// the formula to calculate the BMI index

// check for http://en.wikipedia.org/wiki/Body_mass_index
private float calcularIMC (float peso, float altura) {

return (float) (peso / (altura * altura));
}

// interpret what BMI means
private String interpretIMC(float imcValue) {

imagem = (ImageView)findViewById(R.id.imageBody);

rgsexo = (RadioGroup)findViewById(R.id.rgSexo);
int selectedId = rgsexo.getCheckedRadioButtonId(); // get the id

switch (selectedId) // switch on the button selected
{
case R.id.radioMasc:
if (imcValue < 20) {
imagem.setImageResource(R.drawable.slim);
return "Abaixo do Peso";
} else if (imcValue < 24.9) {
imagem.setImageResource(R.drawable.normal);
return "Peso Normal";
} else if (imcValue < 29.9) {
imagem.setImageResource(R.drawable.fat);
return "Acima do Peso";
} else if (imcValue < 39.9) {
imagem.setImageResource(R.drawable.fat);
return "Obesidade Moderada";
} else {
imagem.setImageResource(R.drawable.fat);
return "Obesidade Mórbida";
}
case R.id.radioFem:
if (imcValue < 19) {
return "Abaixo do Peso";
} else if (imcValue < 23.9) {

return "Peso Normal";
} else if (imcValue < 28.9) {

return "Acima do Peso";
} else if (imcValue < 38.9) {

return "Obesidade Moderada";
} else {
return "Obesidade Mórbida";
}
}
return null;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

}

错误:TextView 类型的 SetText(String) 方法未定义

感谢大家的支持:)

最佳答案

它是 imcI​​nterpreter.setText 小写 s,而不是 imcI​​nterpreter.SetText

关于java - SetText 显示文本不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22238881/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com