Putting double value into TextView - android

In my Android app I am calculating a double value using values entered into EditTexts and trying to put the answer into a TextView. My code is this:
double scoreDouble;
TextView score;
EditText gpa;
EditText sat;
EditText act;
Button calc;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gpa = (EditText) findViewById(R.id.gpa);
String gpaString = gpa.getText().toString();
if(gpaString.equals("")){
gpaString = "0";
}
final double gpaDouble = Double.parseDouble(gpaString);
sat = (EditText) findViewById(R.id.sat);
String satString = sat.getText().toString();
if(satString.equals("")){
satString = "0";
}
final int satInt = Integer.parseInt(satString);
act = (EditText) findViewById(R.id.act);
String actString = act.getText().toString();
if(actString.equals("")){
actString = "0";
}
final int actInt = Integer.parseInt(actString);
score = (TextView) findViewById(R.id.score);
calc = (Button) findViewById(R.id.calc);
calc.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if(actInt/36>satInt/2400){
scoreDouble= (0.6*gpaDouble*25)+(0.4*(actInt/36)*100);
String scoreString = Double.toString(scoreDouble);
score.setText("Your score is "+scoreString);
}else{
scoreDouble = (0.6*gpaDouble*25)+(0.4*(satInt/2400)*100);
String scoreString = Double.toString(scoreDouble);
score.setText("Your score is "+scoreString);
}
}
});
}
As of now, when the button is pressed the TextView says: "Your score is 0.0." I feel this has something to do with the fact that I set the default values of the EditTexts to 0. Before I did this, I was getting an error stating NumberFormatException: invalid double: "". If this is the problem, how should I fix it. If that is not the problem, what it?

You define the actInt and satInt as final variables, and they will be assigned to a value only once (when the execution of the onCreate method) and the initial value will be zero as at the begining the edittext contain nothing.
To solve this issue:
move he actInt and satInt from local variables to a field variables and remove the final keyword. (I mean define those variables as a private variables inside the class) and assign the values for the variables inside the onclick Method.
public class test extends Activity {
double scoreDouble;
TextView score;
EditText gpa;
EditText sat;
EditText act;
Button calc;
private int satInt;
private int actInt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gpa = (EditText) findViewById(R.id.gpa);
sat = (EditText) findViewById(R.id.sat);
act = (EditText) findViewById(R.id.act);
score = (TextView) findViewById(R.id.score);
calc = (Button) findViewById(R.id.calc);
calc.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String gpaString = gpa.getText().toString();
if (gpaString.equals("")) {
gpaString = "0";
}
double gpaDouble = Double.parseDouble(gpaString);
String satString = sat.getText().toString();
if (satString.equals("")) {
satString = "0";
}
int satInt = Integer.parseInt(satString);
String actString = act.getText().toString();
if (actString.equals("")) {
actString = "0";
}
int actInt = Integer.parseInt(actString);
if (actInt / 36 > satInt / 2400) {
scoreDouble = (0.6 * gpaDouble * 25)
+ (0.4 * (actInt / 36) * 100);
String scoreString = Double.toString(scoreDouble);
score.setText("Your score is " + scoreString);
} else {
scoreDouble = (0.6 * gpaDouble * 25)
+ (0.4 * (satInt / 2400) * 100);
String scoreString = Double.toString(scoreDouble);
score.setText("Your score is " + scoreString);
}
}
});
}
}

You are doing everything on your onCreate method. So all your code is called at the start of your application. At this moment, your EditTexts are empty and your code goes to these parts:
if(gpaString.equals("")){
gpaString = "0";
}
if(actString.equals("")){
actString = "0";
}
if (actString.equals("")) {
actString = "0";
}
Which means that your values gpaDouble, actInt and satInt are equals 0.
Then, you are doing the following:
scoreDouble = (0.6*gpaDouble*25)+(0.4*(satInt/36)*100);
and this:
scoreDouble = (0.6*gpaDouble*25)+(0.4*(satInt/2400)*100);
With the 0 values, your scoreDouble value can only be equal to 0.
To fix it, get your EditTexts' texts in the onClick method of your Button.

Related

I'm repeatedly getting the initialized value after using if statement in android studio

I've just started off learning Adroid studio and coding with Java. I'm not sure why my if statement returns a value of 0(The initialized value).
The code above the onclicklistener works fine.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_thecart);
Intent caller = getIntent();
String item = caller.getStringExtra("choice");
TextView disptext = (TextView) findViewById(R.id.carttoptext);
disptext.setText("You selected " + item);
EditText quantity = (EditText) findViewById(R.id.inputquantity);
Button calc= (Button) findViewById(R.id.calc);
calc.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
double price=0;
double vquant = valueOf(quantity.getText().toString());
String item = caller.getStringExtra("choice");
if (item.equals("Eggs")) {
price = vquant * 4;
} else if (item.equals("Milk")) {
price = vquant * 30;
} else if (item.equals("Bread")) {
price = vquant * 23;
} else if (item.equals("Chips")) {
price = vquant * 20;
} else if (item.equals("Maggi")) {
price = vquant * 15;
}
DecimalFormat formatval = new DecimalFormat("##.##");
TextView pricetext = (TextView) findViewById(R.id.pricetext);
pricetext.setText("Total: " + formatval.format(price));
}
});
}
}
I'm expecting the textview beneath the edittext to give me the value vquant*(if condition value). But I'm getting the Textview as Total: 0 , which is the initializing value.
What changes should I make to the code so that I get desired output?
check if the vquant is able to fetch the value from the quantity as a double.
ValueOf() change the data into String and you are taking that data to a double variable. It won't work. Use Double.valueOf()
Have you tried "Double.parseDouble(..)" instead of valueOf?

Bengali calculator Android studio

I am trying to build a Bengali calculator. Here is the layout of English calculator :
By editing layout I can easily replace English digits with Bengali digits. But when it comes to the calculation i am unable to do it. Like i want it to calculate in Bengali too. e.g it will perform in Bengali like this (২+২=৪) instead of (2+2=4). I have tried the replacing method but it didn't work.
Bengali digits(০ ১ ২ ৩ ৪ ৫ ৬ ৭ ৮ ৯)
English digits(1 2 3 4 5 6 7 8 9)
Thank you for your time.
public class MainActivity extends AppCompatActivity {
private TextView screen;
private String str2, result, str, sign;
private double a, b;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
screen = (TextView) findViewById(R.id.textview);
str = "";
}
public void onclick(View v) {
Button button = (Button) v;
str += button.getText().toString();
screen.setText(str);
a = Double.parseDouble(str);
}
public void onclicksign(View v) {
Button button = (Button) v;
sign = button.getText().toString();
screen.setText(sign);
str = "";
}
public void calculate(View v) {
Button button = (Button) v;
str2 = screen.getText().toString();
b = Double.parseDouble(str2);
if (sign.equals("+")) {
result = a + b + "";
} else if (sign.equals("-")) {
result = a - b + "";
} else if (sign.equals("*")) {
result = a * b + "";
} else if (sign.equals("/")) {
result = a / b + "";
} else {
screen.setText("?????? ???");
}
{
screen.setText(result);
}
}
}
Your code tries to extract numerical values from the text on buttons.
You should write custom Double parser which parses Bengali number text to numerical value.
Also you should write a method which converts numerical double value to Bengali number text. You have to use this method while setting screen text.
public class MainActivity extends AppCompatActivity {
private TextView screen;
private String str2, result, str, sign;
private double a, b;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
screen = (TextView) findViewById(R.id.textview);
str = "";
}
public void onclick(View v) {
Button button = (Button) v;
str += button.getText().toString();
screen.setText(str);
a = BengaliUtils.toDouble(str);
}
public void onclicksign(View v) {
Button button = (Button) v;
sign = button.getText().toString();
screen.setText(sign);
str = "";
}
public void calculate(View v) {
Button button = (Button) v;
str2 = screen.getText().toString();
b = BengaliUtils.toDouble(str2);
if (sign.equals("+")) {
result = a + b + "";
} else if (sign.equals("-")) {
result = a - b + "";
} else if (sign.equals("*")) {
result = a * b + "";
} else if (sign.equals("/")) {
result = a / b + "";
} else {
screen.setText("?????? ???");
}
{
screen.setText(BengaliUtils.toString(result));
}
}
}
class BengaliUtils {
static String toString(double value) {
//TODO implement logic
// You can convert value to regular number text, and then replace each char with the Bengali version. The performance could be improved with better logic.
return text;
}
static double toDouble(String text) {
//TODO implement logic
//You can do that, first replace each Bengali char with normal number char. The use Double.parse on new text. The performance could be improved with better logic.
return value;
}
}
#Override
public void onClick(View view) {
String num = editText.getText().toString();
//split the num
char[] charArray = num.toCharArray();
StringBuilder stringBuilder = new StringBuilder(charArray.length);
// loop and convert using switch case
for (int i=0; i<charArray.length; i++ ){
char character = charArray[i];
switch (character){
case '.':
stringBuilder.append(".");
break;
case '0':
stringBuilder.append("০");
break;
case '1':
stringBuilder.append("১");
break;
}
}
//Final result..
textView.setText(stringBuilder);
}
Try above code...
Here is the output
NOTE
I am taking English numbers from EditText on Button click. You will
have to change that in your code.
Currently, switch can handle 0,1,.(decimal) only. You can easily
add cases for other numbers too.
Please Check this answer too. Convert String to another locale in java

How to get a int and a double from an Edit View and display in a Text View? I'm having a hard time to do it...I already solve the int issue

These are my xml. I have a EditText and a Text View
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/resultado"/>
<EditText
android:id="#+id/a_edit_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Insira a"
android:inputType="number"
android:padding="36dp" />
My java file. I already converted EditText's value to int, I guess. What am I doing wrong?
public class DiagnosticoActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_diagnostico);
// Get a value from a editText
EditText editTextA = (EditText) findViewById(R.id.a_edit_text);
TextView resul = (TextView) findViewById(R.id.resultado);
String variableA = editTextA.getText().toString(); //this will get a string
int a = 0;
try {
a = Integer.parseInt(variableA);// will only work on numeric entries
Log.v("DiagnosticoActivity", "Number a: " + a); // this log doesn't work...why?
resul.setText(""+a); //Added "" here
}
catch (NumberFormatException e) {
// handle incorrect text entry here
} // a will be 0 if exception occurred
}
}
How can I display entered number with TextView?
I Tried this but it ain't worked...What I should do?
public class DiagnosticoActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_diagnostico);
}
public void calcular(View view){
// Get a value from a editText
EditText editTextA = (EditText) findViewById(R.id.a_edit_text);
TextView resul = (TextView) findViewById(R.id.resultado);
String variableA = editTextA.getText().toString(); //this will get a string
int a = 0;
try {
a = Integer.parseInt(variableA);// will only work on numeric entries
Log.v("DiagnosticoActivity", "Number a: " + a); // this log doesn't work...why?
resul.setText(a);
}
catch (NumberFormatException e) {
// handle incorrect text entry here
} // a will be 0 if exception occurred
}
}
<Button
android:id="#+id/button_calcular"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calcular"
android:layout_marginRight="8dp"
android:onClick="calcular"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/resultado"/>
<EditText
android:id="#+id/a_edit_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="Insira a"
android:inputType="number"
android:padding="36dp" />
 
New java code
public class DiagnosticoActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_diagnostico);
}
public void calcular(View view){
// Get a value from a editText
EditText editTextA = (EditText) findViewById(R.id.a_edit_text);
TextView resul = (TextView) findViewById(R.id.resultado);
String variableA = editTextA.getText().toString(); //this will get a string
int a = 0;
try {
a = Integer.parseInt(variableA);// will only work on numeric entries
Log.v("DiagnosticoActivity", "Number a: " + a); // this log doesn't work...why?
resul.setText(""+a); //Added "" here
}
catch (NumberFormatException e) {
// handle incorrect text entry here
} // a will be 0 if exception occurred
}
}
Now I want to get a string to a edit view, cast in a double and display into a text view...But my apps crashs!
public class DiagnosticoActivity extends AppCompatActivity {
EditText editTextA;
EditText editTextB;
EditText editTextC;
EditText editTextD;
TextView result;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_diagnostico);
//Locate a View
editTextA = (EditText) findViewById(R.id.a_edit_text);
editTextB = (EditText) findViewById(R.id.b);
editTextC = (EditText) findViewById(R.id.c);
editTextD = (EditText) findViewById(R.id.d);
result = (TextView) findViewById(R.id.resultado);
}
public void calcular(View view){
// Get a value from a editText
String variableA = editTextA.getText().toString(); //this will get a string
String variableB = editTextB.getText().toString(); //this will get a string
String variableC = editTextC.getText().toString(); //this will get a string
String variableD = editTextD.getText().toString(); //this will get a string
//Cast a String in a int or double
double a = Double.parseDouble(variableA);
int b = Integer.parseInt(variableB);
int c = Integer.parseInt(variableC);
int d = Integer.parseInt(variableD);
double soma = a;
result.setText("" + soma);
/*double soma = a/b;
String finalresult = new Double(soma).toString();
NumberFormat nf = NumberFormat.getInstance();
nf.setMinimumFractionDigits(0);
nf.setMaximumFractionDigits(0);
finalresult= nf.format(result);
textView1.setText(finalresult);*/
/*
double soma = a/b;
String stringDouble= Double.toString(soma);
result.setText("" + stringDouble);*/
/*int a = 0;
int b = 0;
try {
a = Integer.parseInt(variableA);// will only work on numeric entries
b = Integer.parseInt(variableB);// will only work on numeric entries
Log.v("DiagnosticoActivity", "Number a: " + a);
}
catch (NumberFormatException e) {
a = 0; // handle incorrect text entry here
} // a will be 0 if exception occurred*/
}
}
public class DiagnosticoActivity extends AppCompatActivity {
EditText editTextA;
TextView resul;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_diagnostico);
editTextA = (EditText) findViewById(R.id.a_edit_text);
resul = (TextView) findViewById(R.id.resultado);
}
public void calcular(View view){
// Get a value from a editText
String variableA = editTextA.getText().toString(); //this will get a string
resul.setText(variableA);
int a = 0;
try {
a = Integer.parseInt(variableA);// will only work on numeric entries
Log.v("DiagnosticoActivity", "Number a: " + a); // this log doesn't work...why?
}
catch (NumberFormatException e) {
a = 0; // handle incorrect text entry here
} // a will be 0 if exception occurred
}
}

sharedPreference or onSaveInstanceState on an EditText/TextView result

I have a little test project below. All I want to do is save the EditText numbers entered and TextView result (thing1, thing2, result) . What's best? onSaveInstanceState, sharedPreference, or something different like SQLite?
I've frustratingly tried the first two (for probably embarrassingly too long), but couldn't figure it out. Could someone please help by adding it to the code below?
public class MainActivity extends ActionBarActivity {
EditText thing1;
EditText thing2;
TextView result;
double n1=0;
double n2=0;
double total=0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button divideButton = (Button) findViewById(R.id.divideButton);
divideButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
thing1 = (EditText) findViewById(R.id.thing1);
if (TextUtils.isEmpty(thing1.getText().toString())) {
n1 = 0;}
else {
n1= Double.parseDouble(thing1.getText().toString());
}
thing2 = (EditText) findViewById(R.id.thing2);
if (TextUtils.isEmpty(thing2.getText().toString())) {
n2 = 0;}
else {
n2 = Double.parseDouble(thing2.getText().toString());
}
if (n2 !=0){
total = (n1 / n2);}
final double total = ((double)n1/(double)n2);
final TextView result= (TextView) findViewById(R.id.result);
String foo = String.format("%.2f", total);
result.setText(foo);
}
});
final Button addButton = (Button) findViewById(R.id.addButton);
addButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
thing1 = (EditText) findViewById(R.id.thing1);
if (TextUtils.isEmpty(thing1.getText().toString())) {
n1 = 0;}
else {
n1= Double.parseDouble(thing1.getText().toString());
}
thing2 = (EditText) findViewById(R.id.thing2);
if (TextUtils.isEmpty(thing2.getText().toString())) {
n2 = 0;}
else {
n2 = Double.parseDouble(thing2.getText().toString());
}
final double total = (n1+n2);
final TextView result= (TextView) findViewById(R.id.result);
String foo = String.format("%.2f", total);
result.setText(foo);
}
});
final Button subtractButton = (Button) findViewById(R.id.subtractButton);
subtractButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
thing1 = (EditText) findViewById(R.id.thing1);
if (TextUtils.isEmpty(thing1.getText().toString())) {
n1 = 0;}
else {
n1= Double.parseDouble(thing1.getText().toString());
}
thing2 = (EditText) findViewById(R.id.thing2);
if (TextUtils.isEmpty(thing2.getText().toString())) {
n2 = 0;}
else {
n2 = Double.parseDouble(thing2.getText().toString());
}
final double total = (n1-n2);
final TextView result= (TextView) findViewById(R.id.result);
String foo = String.format("%.2f", total);
result.setText(foo);
}
});
final Button multiplyButton = (Button) findViewById(R.id.multiplyButton);
multiplyButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
thing1 = (EditText) findViewById(R.id.thing1);
if (TextUtils.isEmpty(thing1.getText().toString())) {
n1 = 0;}
else {
n1= Double.parseDouble(thing1.getText().toString());
}
thing2 = (EditText) findViewById(R.id.thing2);
if (TextUtils.isEmpty(thing2.getText().toString())) {
n2 = 0;}
else {
n2 = Double.parseDouble(thing2.getText().toString());
}
final double total = (n1*n2);
final TextView result= (TextView) findViewById(R.id.result);
String foo = String.format("%.2f", total);
result.setText(foo);
}
});
}
If you will just use the values later like when you open your application, you
can use the SharedPreferences. Based on your code above you can add the code below
to save your EditText data to SharedPreferences and restore it later.
To save your EditText value:
SharedPreferences sharedPreferences = getApplication().getSharedPreferences("ProjectName", MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("thing1", thing1.getText.toString());
editor.commit();
To get the value from SharedPreferences you can do this in your onCreate function:
SharedPreferences sharedPreferences = getApplication().getSharedPreferences("ProjectName", MODE_PRIVATE);
String sValue = sharedPreferences.getString("thing1", "default");
thing1.setText( sValue );

Unable to access my sharedpreferences and calculate

I made an Android app wherein I receive text and numeric (decimal) values from user in 5 different activities then store them in my sharedpreferences. I am able to restore all values using editor(); in all previous 5 activities.
Now
In final calculation activity I'm restoring all user input (text and numbers) and storing them in string and double variables. performing calculations in below posted code activity;
Problem
I am unable to view results in textview using getText.
Is there anything missing?
public class Xcalculateforall extends Activity {
Button qcbut, coatsolbut;
TextView TVqcbut, TVcoatsolbut, TVbrand;
double tdrum, rqctotal;
String a;
public static String FILE1 = "MyPrefsFile";
SharedPreferences abcPref;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.resultmain);
qcbut = (Button) findViewById(R.id.bQCS);
coatsolbut = (Button) findViewById(R.id.bCSP);
TVqcbut = (TextView) findViewById(R.id.tvQCS);
TVbrand = (TextView) findViewById(R.id.tvBrand);
TVcoatsolbut = (TextView) findViewById(R.id.tvCSP);
abcPref = this.getSharedPreferences(FILE1, 0);
a = abcPref.getString("tA", ""); //receives text value and store in 'a' String
double k = Integer.parseInt(abcPref.getString("tsK", ""));
double l = Integer.parseInt(abcPref.getString("tsL", ""));
double m = Integer.parseInt(abcPref.getString("tsM", ""));
double n = Integer.parseInt(abcPref.getString("tsN", ""));
double o = Integer.parseInt(abcPref.getString("tsO", ""));
double p = Integer.parseInt(abcPref.getString("tsP", ""));
tdrum = 20 / m;
double samv = (tdrum / k) / l;
double samv2 = (Math.sqrt(samv));
double tsample = ((samv2 + 1) * k) * l;
double rmicro = tsample * n;
double rchem = tsample * o;
double rother = tsample * p;
double rinqc = rmicro + rchem + rother;
rqctotal = rinqc - 2;
qcbut.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
TVqcbut.setText(rqctotal + "Days");
TVbrand.setText("" + a);
// Intent results = new Intent("com.traviss.calculate.RESULT");
// startActivity(results);
}
});
}
}
Updating query --- previous activity where i take user input
public class G2J extends Activity {
Button two2five, save2;
EditText edtG, edtH, edtI, edtJ, edtK;
int tG, tH, tI, tJ, tK;
String tsG, tsH, tsI, tsJ, tsK;
public static String FileP2 = "MyPrefsFile";
SharedPreferences abcPref;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.g2j);
two2five = (Button) findViewById(R.id.btp2);
edtG = (EditText) findViewById(R.id.etG);
edtH = (EditText) findViewById(R.id.etH);
edtI = (EditText) findViewById(R.id.etI);
edtJ = (EditText) findViewById(R.id.etJ);
edtK = (EditText) findViewById(R.id.etK);
abcPref = getSharedPreferences(FileP2, 0);
edtG.setText(abcPref.getString("tsG", ""));
edtH.setText(abcPref.getString("tsH", ""));
edtI.setText(abcPref.getString("tsI", ""));
edtJ.setText(abcPref.getString("tsJ", ""));
edtK.setText(abcPref.getString("tsK", ""));
two2five.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if ((!edtG.getText().toString().equals(""))
&& (!edtH.getText().toString().equals(""))
&& (!edtI.getText().toString().equals(""))
&& (!edtJ.getText().toString().equals(""))
&& (!edtK.getText().toString().equals(""))) {
abcPref = G2J.this.getSharedPreferences(FileP2, 0);
SharedPreferences.Editor editor = abcPref.edit();
editor.putString("tsG", edtG.getText().toString());
editor.putString("tsH", edtH.getText().toString());
editor.putString("tsI", edtI.getText().toString());
editor.putString("tsJ", edtJ.getText().toString());
editor.putString("tsK", edtK.getText().toString());
editor.commit();
Toast message = Toast.makeText(G2J.this, "Values are saved", 2000);
message.setGravity(Gravity.BOTTOM, 0, 0);
message.show();
Intent openl2p = new Intent("com.traviss.calculate.L2P");
startActivity(openl2p);
}
else {
Toast failz = Toast.makeText(G2J.this,
"Values are not Entered", 2000);
failz.setGravity(Gravity.BOTTOM, 0, 0);
failz.show();
}
};
});
}
}
check your string variables and xml layout
Try -
int k = Integer.parseInt(abcPref.getString("tsK", ""));
You wont get decimal values using Integer.parseInt(String)
Do this
double k = Double.parseDouble(abcPref.getString("tsK", ""));
a = String.valueOf(abcPref.getString("tA", ""));

Categories

Resources