我试图制作一个应用程序,使用spinners将距离/面积/体积转换为单位选择方法。计算意味着完成,然后根据输入到EditText中的内容将输出发送到textview。但是输出只有0.0而没有别的。任何人都可以帮忙吗?为什么不能让这些计算显示在textview上?
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
switch(pos){
case 0:
option1.setAdapter(length);
option2.setAdapter(length);
return;
case 1:
option1.setAdapter(area);
option2.setAdapter(area);
return;
default:
}
}
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing.
}
});
option1.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
if(pos>=0) {
stringInput = edittext1.getText().toString();
if(stringInput == null || stringInput.isEmpty()) {
doubleInput = 0.0;
}
else {
doubleInput = Double.parseDouble(edittext1.getText().toString());
}
}
}
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing.
}
});
option2.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
switch(pos) {
case 0:
miles = doubleInput * 1;
textview1.setText("" + String.valueOf(miles));
return;
case 1:
km = doubleInput * 1.609344;
textview1.setText("" + String.valueOf(km));
return;
default:
}
}
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing.
}
});
谢谢了很多这有助于大规模。那么它不是我的大学工作,但我才刚刚开始在大学学习Java和我一直想,因为得到一个Nexus One的,所以我想ID必须在东西比所提供的网络上最教程更复杂去开发Android。再次感谢 – 2012-01-05 01:07:31
没问题...ActionBar没有做任何有用的事情......如果这不是Uni/College作业,你可能会发现RoboGuice对你的android应用程序有用......然后,如果你刚刚学习Java可能是太过分了。 Nexus One的开发也意味着您可能无法使用ICS。开发早期版本的Android在我看来令人沮丧!祝你好运! – 0909EM 2012-01-05 01:15:56
Ive在我的nexus one 4.0.3上获得了ICS,与XDA Developers的开发者完全相同。所以我想为什么不先开发ICS然后让它在老版本的Android上工作。再次感谢 – 2012-01-05 01:21:23