Basically, I have a navigation bar activity consisting of fragments, and I am making a unit converter. I've got the concept of how to do that cleared, just have one simple issue. Since I'm using radiobuttons, every time I change the value to be converted for the same unit conversion, I need to click on a different radiobutton and then click back on the same radiobutton
final RadioGroup radioGroup = (RadioGroup) myView.findViewById(R.id.radio);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, final int checkedId) {
// checkedId is the RadioButton selected
switch (checkedId) {
case R.id.radioGram:
final TextView textView = (TextView) myView.findViewById(R.id.EditTextFrom);
textView.setText("Gram");
final RadioGroup radioGroup = (RadioGroup) myView.findViewById(R.id.radio2);
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId2) {
switch (checkedId2) {
case R.id.radioGram2:
TextView textView = (TextView) myView.findViewById(R.id.EditTextTo);
textView.setText("Gram");
EditText calc = (EditText) myView.findViewById(R.id.From);
String gramholder = calc.getText().toString();
gram = Integer.parseInt(gramholder) * 1;
EditText editText = (EditText) myView.findViewById(R.id.To);
editText.setText(String.valueOf(gram));
break;
case R.id.radioKilogram2:
TextView textView2 = (TextView) myView.findViewById(R.id.EditTextTo);
textView2.setText("Kilogram");
EditText calc2 = (EditText) myView.findViewById(R.id.From);
String gramholder2 = calc2.getText().toString();
gram2 = Integer.parseInt(gramholder2) * 0.001;
EditText editText2 = (EditText) myView.findViewById(R.id.To);
editText2.setText(String.valueOf(gram2));
break;
}
}
});
So for example, if I want to convert 500 grams to kilograms, I'd just click on the radiobuttons gram (in the first radiogroup) and kilogram (in the second radiogroup), but then if I want to convert 520 grams to kilograms, I would need to click on gram and then back to kilogram in the second radiogroup