Eu quero armazenar em um banco de dados os floats gf e mf.
Meu codigo :
package com.gustavo.sample;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
Button send;
TextView say;
EditText num;
CheckBox g;
CheckBox m;
float gf = 0;
float mf = 0;
@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();
if (counter.equals("")) {
Toast.makeText(getApplicationContext(),
"Digite um valor numerico", Toast.LENGTH_SHORT)
.show();
} else {
float counterAsFloat = Float.parseFloat(counter);
if (g.isChecked() && m.isChecked()) {
Toast.makeText(getApplicationContext(),
"Selecione apenas um checkbox",
Toast.LENGTH_SHORT).show();
} else if (m.isChecked()) {
mf = mf + counterAsFloat;
say.setText("Math " + Float.toString(mf));
} else if (g.isChecked()) {
gf = gf + counterAsFloat;
say.setText("Geo " + Float.toString(gf));
} else
Toast.makeText(getApplicationContext(),
"Selecione um checkbox", Toast.LENGTH_SHORT)
.show();
}
}
});
}
private 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);
}
}