所以我的问题是我试图制作一个转换测量的应用程序,每次按下计算它只是一直给我我的吐司说"无法转换为相同类型&#34 ;而且我没有转换成相同的类型!我不知道为什么这样做!我有一件事要把米改成厘米,它应该可以工作,但是当我在我的旋转器中这样做时,它并没有。我正在使用Android 4.1.2 API 16.在LG L9 p769 T-Mobile上进行测试。我还试过清理它一切都行不通我在代码中没有看到任何错误?
spin1 = (Spinner) findViewById(R.id.spinner1);
et1 = (EditText) findViewById(R.id.editText1);
et2 = (EditText) findViewById(R.id.editText2);
spin2 = (Spinner) findViewById(R.id.spinner2);
spin1.setOnItemSelectedListener (new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> aparent, View arg1,
int pos, long arg3) {
String selectedItem = spin1.getSelectedItem().toString();
if(selectedItem.equals("meter")){
d4 = 1;
}
if(selectedItem.equals("centimeter")){
d4 = 2;
}
if(selectedItem.equals("milimeter")){
d4 = 3;
}
if(selectedItem.equals("yard")){
d4 = 4;
}
if(selectedItem.equals("foot")){
d4 = 5;
}
if(selectedItem.equals("inch")){
d4 = 6;
}
}
public void onNothingSelected(AdapterView<?> aparent) {
d4 = 99;
}
});
spin2.setOnItemSelectedListener (new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> aparent, View arg2,
int pos, long arg4) {
String selectedItem1 = spin1.getSelectedItem().toString();
if(selectedItem1.equals("meter")){
d7 = 1;
}
if(selectedItem1.equals("centimeter")){
d7 = 2;
}
if(selectedItem1.equals("milimeter")){
d7 = 3;
}
if(selectedItem1.equals("yard")){
d7 = 4;
}
if(selectedItem1.equals("foot")){
d7 = 5;
}
if(selectedItem1.equals("inch")){
d7 = 6;
}
}
public void onNothingSelected(AdapterView<?> aparent) {
d7 = 99;
}
});
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater blowUp = getMenuInflater();
blowUp.inflate(R.menu.cool_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case R.id.tcMenu:
Intent e = new Intent(this, MainActivity.class);
startActivity(e);
break;
case R.id.weightMenu:
Intent f = new Intent(this, weight.class);
startActivity(f);
break;
case R.id.mikmMenu:
Intent g = new Intent(this, distance.class);
startActivity(g);
break;
case R.id.measureMenu:
Intent h = new Intent(this, measurement.class);
startActivity(h);
break;
}
return false;
}
public void calCulate(View view){
String d1, d2;
Double d5, d6;
double d3;
Toast itemdupe = Toast.makeText(measurement.this, "Can't convert to same type", Toast.LENGTH_SHORT);
d1 = et1.getText().toString();
d5 = Double.parseDouble(d1);
if(d4 == d7){
itemdupe.show();
}
if((d4 == 1) && (d7 ==2)){
d3 = d5 / 0.010000;
et2.setText("" + d3);
}
}
答案 0 :(得分:0)
spin2.setOnItemSelectedListener (new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> aparent, View arg2,
int pos, long arg4) {
//Should be spin2 below, not spin1 I believe
String selectedItem1 = spin1.getSelectedItem().toString();
你有很多代码重复...