I wanted to add two floats, but I put the first decimal number in EditText
and when I add another decimal number, I put it in EditText
frame in CheckBox
and it continues the same number as I put it in CheckBox
.
Example: I placed 1.5
Then when I delete 1.5% of my EdiText
and put 1.5 more and mark one of CheckBox
It is actually 1.5 instead of getting 3.0 in the result of TextView
.
package com.gustavo.sample;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
CheckBox g;
CheckBox m;
Button send;
TextView say;
EditText num;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bacon();
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String counter = num.getText().toString();
float counterAsFloat = Float.parseFloat(counter);
float geof = 0f;
float matf = 0f;
if(g.isChecked()){
float res1 = geof += counterAsFloat;
say.setText("Geo " + Float.toString(res1));
}
else if(m.isChecked()){
float res2 = matf += counterAsFloat;
say.setText("Math " + Float.toString(res2));
}
}
});
}
public void bacon() {
g = (CheckBox)findViewById(R.id.checkBox1);
m = (CheckBox)findViewById(R.id.checkBox2);
send = (Button)findViewById(R.id.button1);
say = (TextView)findViewById(R.id.textView1);
num = (EditText)findViewById(R.id.editText1);
}
}