私はこれにかなり慣れていないので、なぜこの問題が発生しているのか完全にはわかりません。私のコードから:
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.Toast;
public class MainActivity extends Activity {
RadioButton wavelength1;
RadioButton wavelength2;
double ray;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wavelength1 = (RadioButton) findViewById(R.id.lowave);
wavelength2 = (RadioButton) findViewById(R.id.hiwave);
Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
If (wavelength1.isChecked());{
ray = 0.7125;
}
If (wavelength2.isChecked());{
ray = 0.4436;
}
Toast.makeText(MainActivity.this, String.valueOf(ray), Toast.LENGTH_LONG).show();
}
private void If(boolean checked) {
// TODO Auto-generated method stub
}
});
}
}
どちらかのラジオ ボックスをクリックすると、異なるはずのトーストに同じ出力が (0.4436 として) 表示されます。私は何が起こっているのか本当に途方に暮れています。このアプリは API 10 を対象としており、Eclipse を使用しています。(私は何かが欠けていると確信しています)。