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 );
Related
I need to pick a button, 'H' which represents the atomic element in periodic table, as many times as needed, and it has to add up the overall weight number, and display it in the mw_results.
So far, I am only able to display it, for two times, as I had hard coded it the value.
Any ideas how I could keep adding the number, without hard coding it..?
Thanks.!
Below is the code:
public void Chem()
{
final Dialog g = new Dialog(Sol.this);
g.setContentView(R.layout.table);
final float[] MoWeight = {0};
mw_result = (TextView)findViewById(R.id.editText);
mf_result = (EditText)findViewById(R.id.editText4);
Chemname = "";
final String space = " ";
final int number = 0;
Button H = (Button) g.findViewById(R.id.H);
Button C = (Button) g.findViewById(R.id.C);
H.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.H:
mf_result.append(String.valueOf("H"));
mw_result.setText(String.valueOf(123));
float MoWeight = Float.valueOf(mw_result.getText().toString());
MoWeight = Float.valueOf(mw_result.getText().toString()) + MoWeight;
String mw_res=Float.toString(MoWeight);
mw_result.setText(mw_res);
mw_result = (TextView)findViewById(R.id.editText);
g.dismiss();
}
}
});
C.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.C:
mf_result.append(String.valueOf("C"));
mw_result.setText(String.valueOf(456));
float MoWeight = Float.valueOf(mw_result.getText().toString());
MoWeight = Float.valueOf(mw_result.getText().toString()) + MoWeight;
String mw_res=Float.toString(MoWeight);
mw_result.setText(mw_res);
mw_result = (TextView)findViewById(R.id.editText);
g.dismiss();
}
}
});
g.show();
}
It seems like you're resetting the text view back to 123 and 456 respectively on each click.
It's kinda hard to see exactly what you want, but this might help you to get on the right track:
public void Chem()
{
final Dialog g = new Dialog(Sol.this);
g.setContentView(R.layout.table);
final float[] MoWeightArray = {0}; //rename this for readability -- is this used at all?
mw_result = (TextView)findViewById(R.id.editText);
mf_result = (EditText)findViewById(R.id.editText4);
Chemname = "";
final String space = " ";
final int number = 0;
Button H = (Button) g.findViewById(R.id.H);
Button C = (Button) g.findViewById(R.id.C);
H.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.H:
String sMW= mw_result.getText().toString();
mf_result.append(String.valueOf("H"));
if (sMW.matches("")) {
mw_result.setText(String.valueOf(123));
}
else{
float MoWeight = Float.valueOf(sMW);
MoWeight += 123;
String mw_res=Float.toString(MoWeight);
mw_result.setText(mw_res);
//mw_result = (TextView)findViewById(R.id.editText); no need for this
g.dismiss();
}
}
}
});
C.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.C:
String sMW= mw_result.getText().toString();
mf_result.append(String.valueOf("C"));
if (sMW.matches("")) {
mw_result.setText(String.valueOf(456));
}
else{
float MoWeight = Float.valueOf(sMW);
MoWeight += 456;
String mw_res=Float.toString(MoWeight);
mw_result.setText(mw_res);
//mw_result = (TextView)findViewById(R.id.editText); No need for this
g.dismiss();
}
}
}
});
g.show();
}
Try this:
public void Chem()
{
final Dialog g = new Dialog(Sol.this);
g.setContentView(R.layout.table);
final float[] MoWeight = {0};
mw_result = (TextView)findViewById(R.id.editText);
mf_result = (EditText)findViewById(R.id.editText4);
Chemname = "";
final String space = " ";
final int number = 0;
Button H = (Button) g.findViewById(R.id.H);
Button C = (Button) g.findViewById(R.id.C);
mw_result.setTag(1);//1 in case you're updating 123 values
mw_result.setTag(2);//2 in case you're updating 456 values
H.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int key = Integer.parseInt(mw_result.getTag().toString());
if(key==2){
mw_result.setTag(1);//1 in case you're updating 123 values
mf_result.append(String.valueOf("H"));
mw_result.setText(String.valueOf(123));
g.dismiss();
}
else{
float MoWeight = Float.valueOf(mw_result.getText().toString());
MoWeight = Float.valueOf(mw_result.getText().toString()) + 1;
String mw_res=Float.toString(MoWeight);
mw_result.setText(mw_res);
}
}
});
C.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
int key = Integer.parseInt(mw_result.getTag().toString());
if(key==1){
mw_result.setTag(2);//1 in case you're updating 123 values
mf_result.append(String.valueOf("C"));
mw_result.setText(String.valueOf(456));
g.dismiss();
}
else{
float MoWeight = Float.valueOf(mw_result.getText().toString());
MoWeight = Float.valueOf(mw_result.getText().toString()) + 1;
String mw_res=Float.toString(MoWeight);
mw_result.setText(mw_res);
}
}
});
g.show();
}
I have a simple shop activity which uses SharedPreferences to store various data. The problem is that when I click on purchase, I can purchase it multiple times and each time it takes the money from the coins value away. Please help me with this.
This is my code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.shop_layout);
ImageButton lives = (ImageButton) findViewById(R.id.lives);
final Button hardmode = (Button) findViewById(R.id.hardmode);
final Button reversedMode = (Button) findViewById(R.id.reversedmode);
final SharedPreferences shop = getSharedPreferences("Shop", Context.MODE_PRIVATE);
final int[] livesPrice = {shop.getInt("livesPrice", 10)};
final int[] hardmodePrice = {shop.getInt("hardmodePrice", 15)};
final int[] reversedModePrice = {shop.getInt("reverseModePrice", 20)};
final int[] coins = {shop.getInt("money", 10000)};
final boolean[] hardmodeBoolean = {shop.getBoolean("hardmode", false)};
final boolean[] reversedModeBoolean = {shop.getBoolean("reversedMode", false)};
if(hardmodeBoolean[0]){
hardmode.setText("Purchased");
}
if(reversedModeBoolean[0]){
reversedMode.setText("Purchased");
}
TextView price1 = (TextView) findViewById(R.id.price1);
final TextView money = (TextView) findViewById(R.id.money);
Typeface tf = Typeface.createFromAsset(getAssets(), "font/cricket.ttf");
price1.setTypeface(tf);
price1.setText("=" + livesPrice[0]);
money.setTypeface(tf);
money.setText("Coins " + String.valueOf(coins[0]));
lives.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (coins[0] >= livesPrice[0]) {
coins[0] = coins[0] - livesPrice[0];
livesPrice[0] = livesPrice[0] + 10;
int numberOfLives = shop.getInt("numberOfLives", 1);
numberOfLives = numberOfLives + 1;
SharedPreferences.Editor editor = shop.edit();
editor.putInt("numberOfLives", numberOfLives);
editor.putInt("money", coins[0]);
editor.commit();
money.setText("Coins " + String.valueOf(coins[0]));
}
}
});
hardmode.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
SharedPreferences.Editor editor = shop.edit();
if (coins[0] >= hardmodePrice[0]) {
coins[0] = coins[0] - hardmodePrice[0];
editor.putBoolean("hardmode", true);
editor.putInt("hardmodePrice", 0);
editor.putInt("money", coins[0]);
editor.apply();
money.setText("Coins " + String.valueOf(coins[0]));
hardmode.setText("Purchased");
hardmodeBoolean[0] = shop.getBoolean("hardmode", true);
}
}
});
reversedMode.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
SharedPreferences.Editor editor = shop.edit();
if (coins[0] >= reversedModePrice[0]) {
coins[0] = coins[0] - reversedModePrice[0];
editor.putBoolean("reversedMode", true);
editor.putInt("reversedModePrice", 0);
editor.putInt("money", coins[0]);
editor.apply();
money.setText("Coins " + String.valueOf(coins[0]));
reversedMode.setText("Purchased");
reversedModeBoolean[0] = shop.getBoolean("reversedMode", true);
}
}
});
}
try changing
coins[0] = coins[0] - livesPrice[0];
To
coins[0] -= livesPrice[0] ;
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.
Hi all I am having a little trouble handling this question. I have 5 EditText boxes and I ask the user to put a number in them. Then I want to calculate the sum of the EditText boxes and do something with the sum. However I am having trouble in the case if the user don't put a number in all the boxes.
Is it possible to put a default value "0" in the boxes just in case not all the boxes are filled but the sum to be calculated although not all the boxes are filled?
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_extra_question);
textBox1 = (EditText) findViewById(R.id.editText1);
textBox2 = (EditText) findViewById(R.id.editText2);
textBox3 = (EditText) findViewById(R.id.editText3);
textBox4 = (EditText) findViewById(R.id.editText4);
textBox5 = (EditText) findViewById(R.id.editText5);
buttON = (Button) findViewById(R.id.button1);
buttON.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
number1 = Integer.parseInt(textBox1.getText().toString());
number2 = Integer.parseInt(textBox2.getText().toString());
number3 = Integer.parseInt(textBox3.getText().toString());
number4 = Integer.parseInt(textBox4.getText().toString());
number5 = Integer.parseInt(textBox5.getText().toString());
sum = number1 + number2 + number3 + number4 + number5;
if(sum > 100)
{
Toast.makeText(getApplicationContext(), "Nice!", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getApplicationContext(), "Fail!", Toast.LENGTH_LONG).show();
}
}
});
Do this for each number:
number1 = textBox1.getText().toString().trim().isEmpty()?0:Integer.parseInt(textBox1.getText().trim().toString());
Create on function like this
public int getIntFromString(String str) {
if (str != null) {
if (str.equalsIgnoreCase("")) {
return 0;
} else {
try {
return Integer.parseInt(str);
} catch (NumberFormatException e) {
return 0;
}
}
} else {
return 0;
}
}
Then Your code should be
number1 = getIntFromString(textBox1.getText().toString().trim());
number2 = getIntFromString(textBox2.getText().toString().trim());
number3 = getIntFromString(textBox3.getText().toString().trim());
number4 = getIntFromString(textBox4.getText().toString().trim());
number5 = getIntFromString(textBox5.getText().toString().trim());
Yes your idea is correct. For each of the edit texts , just check:
if(textBox1.getText().toString().equals(""))
{
number1 = 0;
}
else
number1 = Integer.parseInt(textBox1.getText().toString());
You have to check Empty String using the below code and put "0" in every missing value.
number1 = textBox1.getText().toString().isEmpty()?0:Integer.parseInt(textBox1.getText().toString());
number2 = textBox2.getText().toString().isEmpty()?0:Integer.parseInt(textBox2.getText().toString());
number3 = textBox3.getText().toString().isEmpty()?0:Integer.parseInt(textBox3.getText().toString());
number4 = textBox4.getText().toString().isEmpty()?0:Integer.parseInt(textBox4.getText().toString());
number5 = textBox5.getText().toString().isEmpty()?0:Integer.parseInt(textBox5.getText().toString());
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", ""));