谢谢你们帮我解决了搜索栏问题...我相信大部分问题都已修复,但有2个新错误...我很抱歉。
public class MainActivity extends Activity {
private RadioGroup rgsexo;
EditText editPeso;
EditText editAltura;
TextView imcView;
SeekBar alterarAltura;
SeekBar alterarPeso;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
alterarAltura.setOnSeekBarChangeListener(alteraralturaListener);
editPeso = (EditText)findViewById(R.id.editPeso);
editAltura = (EditText)findViewById(R.id.editAltura);
imcView = (TextView)findViewById(R.id.imcView);
alterarAltura = (SeekBar)findViewById(R.id.alterarAltura);
alterarPeso = (SeekBar)findViewById(R.id.alterarPeso);
alterarAltura.setOnSeekBarChangeListener(alteraralturaListener);
}
private OnSeekBarChangeListener alteraralturaListener = new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
// Calcula o novo valor do TIP
editAltura=(alterarAltura.getProgress()) * .01;
// mostra na caixa o valor novo
alterarAltura.setText(String.format("%.02f", editAltura).replace(',', '.'));
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
};
错误是
“editAltura =(alterarAltura.getProgress())* .01;” 输入missmatch,无法将edittext转换为double
“alterarAltura.setText(String.format(”%。02f“,editAltura).replace(',','。'));” 对于SeekBar类型
,未定义setText(String)的方法我做错了吗?
答案 0 :(得分:2)
alterarAltura.setOnSeekBarChangeListener(alteraralturaListener);
需要位于方法内(例如onCreate(...)
)。
答案 1 :(得分:1)
你设置了错误的变量:alterarAltura是一个SeekBar。将其复制到onProgressChanged:
double myDouble = (alterarAltura.getProgress()) * .01d;
// mostra na caixa o valor novo
editAltura.setText(String.format("%.02f", myDouble).replace(',', '.'));
答案 2 :(得分:0)
首先,重新排列您的活动代码,然后说出您面临的问题。
public class MainActivity extends Activity {
private RadioGroup rgsexo;
EditText editPeso;
EditText editAltura;
TextView imcView;
SeekBar alterarAltura;
SeekBar alterarPeso;
alterarAltura.setOnSeekBarChangeListener(alteraralturaListener);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.your_layout);
editPeso = (EditText)findViewById(R.id.editPeso);
editAltura = (EditText)findViewById(R.id.editAltura);
imcView = (TextView)findViewById(R.id.imcView);
alterarAltura = (SeekBar)findViewById(R.id.alterarAltura);
alterarPeso = (SeekBar)findViewById(R.id.alterarPeso);
alterarAltura.setOnSeekBarChangeListener(alteraralturaListener);
}
private OnSeekBarChangeListener alteraralturaListener = new OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
// TODO Auto-generated method stub
// Calcula o novo valor do TIP
editAltura=(alterarAltura.getProgress()) * .01;
// mostra na caixa o valor novo
alterarAltura.setText(String.format("%.02f", editAltura).replace(',', '.'));
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
};
}