Hey everyone, I am in need of some help with my first android app, and I have a little experience in programming. So first I wanted to do was something like “Let the user choose whichever method they want to convert from and to, and let them input the value in the TextView then follow by pressing the convert button to finish it with a toast.”
Currently I am having trouble with onClickListener() button to finish of with a toast output, I can’t get the result from the String in switch/case. Also I am not sure that if my code is okay, as I cannot test it :(. I Spent hours trying to get it work but no luck. Need someone to point me to the right direction and what I need to look at, please.
class convert_handler_CMtoM implements Button.OnClickListener {
public void onClick(View v) {
if (v == btnDisplay) {
if (MMtoCM.isChecked())
{
int Amount = (int) Float.parseFloat(et1.getText().toString());
int formula = (int) (Amount * 10) ;
String result = String.valueOf(formula);
}
if (CMtoMM.isChecked())
{
double Amount = (double)Float.parseFloat(et1.getText().toString());
double formula = (double) (Amount / 10) ;
String result = String.valueOf(formula);
}
}
}
private OnClickListener btnDisplay = new OnClickListener() {
public void onClick(View v) {
// Perform action on clicks
RadioButton rb = (RadioButton) v;
Toast.makeText(second.this, rb.getText(), result, Toast.LENGTH_SHORT).show();
}
};
}
1 Answer