Value stored in shared preferences is not being reflected - android

package com.example.shared;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
Button bshared;
TextView tv;
String x;
SharedPreferences pref;
Editor edit;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bshared = (Button) findViewById(R.id.bshared);
tv = (TextView) findViewById(R.id.tv);
tv.setText(x);
bshared.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
pref=getApplicationContext().getSharedPreferences("details",1);
edit = pref.edit();
edit.clear();
edit.putString("name", "These are new values");
edit.commit();
x = pref.getString("name", "");
}
});
}
}
When i click on the button the value of textview must change to 'These are new values', but that is not happening. Can someone help me find my mistake ?

In on Click Method you have to set value to textview like below code.
pref=getApplicationContext().getSharedPreferences("details",1);
x = pref.getString("name", "");
tv.setText(x);
bshared.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v)
{
edit = pref.edit();
edit.clear();
edit.putString("name", "These are new values");
edit.commit();
x = pref.getString("name", "");
tv.setText(x);
}
});

The textview is setting the text before you change your text. So it will not be reflected in the textview. add this line to last of onclick method after you change value of the string.
tv.setText(x);
EDIT:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bshared = (Button) findViewById(R.id.bshared);
tv = (TextView) findViewById(R.id.tv);
pref=getApplicationContext().getSharedPreferences("details",1);
x = pref.getString("name", "");
tv.setText(x);
bshared.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
edit = pref.edit();
edit.clear();
edit.putString("name", "These are new values");
edit.commit();
x = pref.getString("name", "");
tv.setText(x);
}
});
}
}

Related

Sharedprefrences not saving?

When i try to save a variable to shared preferences then call it in an editext it is not being saved? I've been looking around for hours but i cannot find anything on it. I know that sharedPrefrences acts like a dictionary in a way but other than that i don't understand why this is not working :(
package com.example.gatorblocks;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.wearable.activity.WearableActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class block1Settings extends WearableActivity{
private TextView mTextView;
Context context = this;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_block1_settings);
configureBackButton();
configureColor();
Button addTextButton = (Button) findViewById(R.id.Apply);
TextView simpleEditText = findViewById(R.id.simpleEditText);
SharedPreferences prefs = getSharedPreferences("classes.txt", 0);
simpleEditText.setText(prefs.getString("classes1","1-1")); //set textbox to equal current class
final EditText vEditText = (EditText) findViewById(R.id.simpleEditText);
mTextView = (TextView) findViewById(R.id.text);
// Enables Always-on
setAmbientEnabled();
addTextButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String enteredText = vEditText.getText().toString(); //sets the array value of block to the editText
test(enteredText);
}
});
}
private void configureColor() {
Button Block1 = (Button) findViewById(R.id.colorButton);
Block1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(block1Settings.this, colorBlock1.class));
overridePendingTransition(R.anim.slide_in_right,R.anim.slide_out_left);
}
});
}
private void configureBackButton(){
Button backbutton = (Button) findViewById(R.id.backButton);
backbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(block1Settings.this, classes.class));
overridePendingTransition(R.anim.slide_in_left,R.anim.slide_out_right);
finish();
}
});
}
public void test(String enteredText){
SharedPreferences pref = getSharedPreferences("classes.txt", 0);
SharedPreferences.Editor editor = pref.edit();
editor.putString("class1", enteredText);
editor.apply();
}
}
How did you get data from SharedPreferences which is not saved? You saved data using key class1 and want to get it by classes1 which is not correct way. You have to use same key. Try using
SharedPreferences prefs = getSharedPreferences("classes.txt", 0);
simpleEditText.setText(prefs.getString("class1","1-1"));

Change & Save Button Text onLongClick using sharedpreferences

I want to change & save button text onLongClick permanently(until & unless I change it again). This is screenshot of overall code. But when I close the App & reopen it, the Button text remains default. What mistake am I doing?
package com.demo.buttontextedit;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
SharedPreferences sharedPreferences;
private Button btn;
private EditText edit;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn = (Button) findViewById(R.id.button);
edit = (EditText) findViewById(R.id.edit_text);
btn.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
showDialog(edit.getText().toString());
return true;
}
});
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "You clicked Button" +
btn.getText().toString(), Toast.LENGTH_SHORT).show();
}
});
}
private void showDialog(String str) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("input text");
View view = LayoutInflater.from(this).inflate(R.layout.dialog_view, null);
final EditText edit_dialog = (EditText) view.findViewById(R.id.edit_dialog);
edit_dialog.setText(str);
builder.setView(view);
builder.setNegativeButton("cancel", null);
builder.setPositiveButton("confirm", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
sharedPreferences = getSharedPreferences("myPref", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("Name", edit_dialog.getText().toString());
editor.commit();
btn.setText(sharedPreferences.getString("Name", ""));
}
});
builder.show();
}
}
you are missing get text from shared preferences on Oncrete activity.
Solution
put this lines :
if (sharedPreferences.getString("Name", "").equals(""))
{
btn.setText("YES");
}else{
btn.setText(sharedPreferences.getString("Name", "YES"));
}
below this line :
btn = (Button) findViewById(R.id.button);
Flow of control causing this behavior.
you need to fetch data from preference in oncreate and set it on the button
like
oncreate(Bundle b) {
// initialize preference and layout
String btntext=sharedPreferences.getString("btnkey","Yes")
btn.setText(btntext);
}
so when application is recreated, you find the stored text from preference and set it on the button and it's done.
The main problem as I can see is that this line:
btn.setText(sharedPreferences.getString("Name", "YES"));
is called before the button is initialized and found in the view. This causes the string to be set to a nullpointer which(if not try-catched) crashes the app. As long as you define the button before you set the text, no nullpointer and text is set.
btn = (Button) findViewById(R.id.button);
btn.setText(sharedPreferences.getString("Name", "YES"));

TextView to display sharedpreference EditText

I'm trying to Save an editText to Sharedprefrences so that it displays in the TextView amnt. It's displaying it but not saving it? what am I doing wrong? I am new to this, just a little weekend hobby so I'm sorry if this is a stupid question, thanks for your time.
package org.iimed.www;
import java.util.Calendar;
import org.iimed.www.DateTimePicker.DateWatcher;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.Dialog;
import android.app.PendingIntent;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.inputmethodservice.Keyboard.Key;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
public class CaAdd extends Activity implements DateWatcher,OnClickListener{
Button button_click,amount;
int amountt = 0;
Key at;
EditText amountedit;
String amountText;
String amountString;
TextView dateResult, date2,amnt;
int hrs,min;
SharedPreferences.Editor editor ;
SharedPreferences prefs;
String amntprefs;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.datetimeactivity);
dateResult = (TextView)findViewById(R.id.textview1);
date2 = (TextView)findViewById(R.id.textView2);
button_click = (Button)findViewById(R.id.setbtn);
button_click.setOnClickListener(this);
amnt = (TextView)findViewById(R.id.amountText);
}
public final String AT = "Amount";
public void loadDefaultSharedPreferences() {
prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs != null) {
String loadUsername= prefs.getString(
AT , null);
if (loadUsername != null && !loadUsername.isEmpty()) {
amnt.setText(loadUsername);
}}}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.setbtn:
final Dialog mDateTimeDialog = new Dialog(this);
// Inflate the root layout
final RelativeLayout mDateTimeDialogView = (RelativeLayout) getLayoutInflater().inflate(R.layout.date_time_dialog, null);
// Grab widget instance
final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView.findViewById(R.id.DateTimePicker);
mDateTimePicker.setDateChangedListener(this);
mDateTimePicker.initData();
amountedit = (EditText)mDateTimeDialogView.findViewById(R.id.amountedit);
ImageButton increase = (ImageButton)mDateTimeDialogView.findViewById(R.id.increase);
increase.setOnClickListener(new OnClickListener(){
public void onClick(View v){
amountt++;
amountText = Integer.toString(amountt);
amountedit.setHint(amountText);
amnt.setText(amountText);
}
});
ImageButton decrease = (ImageButton)mDateTimeDialogView.findViewById(R.id.decrease);
decrease.setOnClickListener(new OnClickListener(){
public void onClick(View v){
amountt--;
amountText = Integer.toString(amountt);
amountedit.setHint(amountText);
amnt.setText(amountText);
}
});
Button setDateBtn = (Button)mDateTimeDialogView.findViewById(R.id.SetDateTime);
// Update demo TextViews when the "OK" button is clicked
setDateBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent=new Intent(CaAdd.this,AlarmReceiver.class);
PendingIntent pi=PendingIntent.getActivity(CaAdd.this, 2, intent,PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alm=(AlarmManager) getSystemService(Context.ALARM_SERVICE);
hrs=mDateTimePicker.getHour();
min=mDateTimePicker.getMinute();
Calendar calendar=Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,hrs);
calendar.set(Calendar.MINUTE, min);
calendar.set(Calendar.SECOND, 0);
alm.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(), pi);
mDateTimePicker.clearFocus();
String result_string = mDateTimePicker.getMonth() + "/" + String.valueOf(mDateTimePicker.getDay()) + "/" + String.valueOf(mDateTimePicker.getYear())
+ " " + String.valueOf(mDateTimePicker.getHour()) + ":" + String.valueOf(mDateTimePicker.getMinute());
if(mDateTimePicker.getHour() > 12) result_string = result_string + "PM";
else result_string = result_string + "AM";
date2.setText(result_string);
mDateTimeDialog.dismiss();
}
});
Button cancelBtn = (Button)mDateTimeDialogView.findViewById(R.id.CancelDialog);
// Cancel the dialog when the "Cancel" button is clicked
cancelBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mDateTimePicker.reset();
mDateTimeDialog.cancel();
}
});
// Reset Date and Time pickers when the "Reset" button is clicked
Button resetBtn = (Button)mDateTimeDialogView.findViewById(R.id.ResetDateTime);
resetBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mDateTimePicker.reset();
}
});
mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Set the dialog content view
mDateTimeDialog.setContentView(mDateTimeDialogView);
//Display the dialog
mDateTimeDialog.show();
}}
public void onDateChanged(Calendar c) {
Log.e("","" + c.get(Calendar.MONTH) + " " + c.get(Calendar.DAY_OF_MONTH)+ " " + c.get(Calendar.YEAR));
String result_string =String.valueOf(c.get(Calendar.MONTH)+1) + "/" + String.valueOf(c.get(Calendar.DAY_OF_MONTH)) + "/" + String.valueOf(c.get(Calendar.YEAR));
// _tvUserDOB.setTypeface(CGlobalVariables.tfFoEnglish);
dateResult.setText(result_string+" (mm/dd/yyyy)");
}
public void saveDefaultPreferences() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);{
SharedPreferences.Editor editor = prefs.edit();
final String AT = "Amount";
editor.putString(AT,amountText);
editor.commit();}
}}
Shared preferences allows you to save and retrieve key, value pair data.
Initialization:
SharedPreferences pref = getApplicationContext().getSharedPreferences("MyPref", 0);
// 0 - for private mode
Editor editor = pref.edit();
Storing Data:
editor.putString("key_name", "string value"); // Storing string
editor.commit(); // commit changes
Retrieving Data:
pref.getString("key_name", null); // getting String
To know more about SharedPreferences or to try out a simple example, check this
You can only save key-value pairs for some of the primitives and String (String set also) only. Android views can never be saved anywhere.
SharedPreferences manager =PreferenceManager.getDefaultSharedPreferences(context);
Use it for saving and retrieving data as follows
// for saving data
manager.edit().putString(context.getString(AT), YOUR_TEXT).commit()
// for retrieving data
manager.getString(context.getString(AT), "");

EditText on touch

I have a DateTimePicker with a little "amount" editext that I save the Sharedpref
but for some reason if I "touch" the EditText and enter the amount in manually, the text is black and doesn't transfer to the TextView, if using the imagebuttons increase and decrease the editText will work as intended. If I enter the dates and times in this manner though it does work, what am I missing?
ImageButton increase = (ImageButton)mDateTimeDialogView.findViewById(R.id.increase);
increase.setOnClickListener(new OnClickListener(){
public void onClick(View v){
amountt++;
amountText = Integer.toString(amountt);
amountedit.setHint(amountText);
amnt.setText(amountText);
editor.putString("numbers", amountText);
editor.commit();
}
});
ImageButton decrease = (ImageButton)mDateTimeDialogView.findViewById(R.id.decrease);
decrease.setOnClickListener(new OnClickListener(){
public void onClick(View v){
amountt--;
amountText = Integer.toString(amountt);
amountedit.setHint(amountText);
amnt.setText(amountText);
editor.putString("numbers", amountText);
editor.commit();
}
});
The relevant EditText info
amountedit=(EditText)mDateTimeDialogView.findViewById(R.id.amountedit);
The TextView it displays to
amnt = (TextView)findViewById(R.id.amountText);
The XML of EditText
<EditText
android:id="#+id/amountedit"
android:layout_width="50dp"
android:key = "amntkey"
android:layout_height="wrap_content"
android:layout_above="#+id/linearLayout1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="62dp"
android:ems="10"
android:inputType="number"
android:persistent="true" />
The complete java activity it takes place:
import java.util.Calendar;
import java.util.HashMap;
import org.iimed.www.DateTimePicker.DateWatcher;
import android.app.Activity;
import android.app.AlarmManager;
import android.app.Dialog;
import android.app.PendingIntent;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.inputmethodservice.Keyboard.Key;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
public class CaAdd extends Activity implements DateWatcher,OnClickListener{
Button button_click;
int amountt = 0;
String amountText;
String number = "numbers";
TextView amnt;
TextView dateResult, date2;
int hrs,min;
SharedPreferences pref;
String time = "time";
String get;
String sTime;
String amount ;
EditText amountedit;
String result_string;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.datetimeactivity);
dateResult = (TextView)findViewById(R.id.textview1);
date2 = (TextView)findViewById(R.id.textView2);
button_click = (Button)findViewById(R.id.setbtn);
pref = getSharedPreferences("prefs", Context.MODE_PRIVATE);
button_click.setOnClickListener(this);
amnt = (TextView)findViewById(R.id.amountText);
pref = getSharedPreferences("prefs", Context.MODE_PRIVATE);
amountText = Integer.toString(amountt);
amount = amnt.toString();
get = pref.getString("numbers",amountText);
sTime = pref.getString("time", result_string);
amnt.setText(get);
date2.setText(sTime) ;
}
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.setbtn:
final Dialog mDateTimeDialog = new Dialog(this);
// Inflate the root layout
final RelativeLayout mDateTimeDialogView = (RelativeLayout) getLayoutInflater().inflate(R.layout.date_time_dialog, null);
// Grab widget instance
final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView.findViewById(R.id.DateTimePicker);
mDateTimePicker.setDateChangedListener(this);
mDateTimePicker.initData();
amountedit=(EditText)mDateTimeDialogView.findViewById(R.id.amountedit);
ImageButton increase = (ImageButton)mDateTimeDialogView.findViewById(R.id.increase);
increase.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Editor editor = pref.edit();
amountt++;
amountText = Integer.toString(amountt);
amountedit.setHint(amountText);
amnt.setText(amountText);
String amount =amnt.toString();
editor.putString("numbers", amountText);
editor.commit();
}
});
ImageButton decrease = (ImageButton)mDateTimeDialogView.findViewById(R.id.decrease);
decrease.setOnClickListener(new OnClickListener(){
public void onClick(View v){
Editor editor = pref.edit();
amountt--;
amountText = Integer.toString(amountt);
amountedit.setHint(amountText);
amnt.setText(amountText);
String edi = amountedit.toString();
editor.putString("numbers", amountText);
editor.commit();
}
});
Button setDateBtn = (Button)mDateTimeDialogView.findViewById(R.id.SetDateTime);
setDateBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent=new Intent(CaAdd.this,AlarmReceiver.class);
PendingIntent pi=PendingIntent.getActivity(CaAdd.this, 2, intent,PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager alm=(AlarmManager) getSystemService(Context.ALARM_SERVICE);
Editor editor = pref.edit();
hrs=mDateTimePicker.getHour();
min=mDateTimePicker.getMinute();
Calendar calendar=Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY,hrs);
calendar.set(Calendar.MINUTE, min);
calendar.set(Calendar.SECOND, 0);
alm.set(AlarmManager.RTC_WAKEUP,calendar.getTimeInMillis(), pi);
mDateTimePicker.clearFocus();
result_string =
String.valueOf(mDateTimePicker.getHour()) + ":" + String.valueOf(mDateTimePicker.getMinute());
if(mDateTimePicker.getHour() > 12) result_string = result_string + "PM";
else result_string = result_string + "AM";
date2.setText(result_string);
editor.putString("time",result_string);
editor.commit();
mDateTimeDialog.dismiss();
}
});
Button cancelBtn = (Button)mDateTimeDialogView.findViewById(R.id.CancelDialog);
cancelBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mDateTimePicker.reset();
mDateTimeDialog.cancel();
}
});
Button resetBtn = (Button)mDateTimeDialogView.findViewById(R.id.ResetDateTime);
resetBtn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mDateTimePicker.reset();
}
});
mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDateTimeDialog.setContentView(mDateTimeDialogView);
mDateTimeDialog.show();}}
public void onDateChanged(Calendar c) {
Log.e("","" + c.get(Calendar.MONTH) + " " + c.get(Calendar.DAY_OF_MONTH)+ " " + c.get(Calendar.YEAR));
String result_string =String.valueOf(c.get(Calendar.MONTH)+1) + "/" + String.valueOf(c.get(Calendar.DAY_OF_MONTH)) + "/" + String.valueOf(c.get(Calendar.YEAR));
dateResult.setText(null);
}}
Your code isn't clear, you should post code about that EditText you're talking about.
BTW, to get what you would like, you can try to do Sharedpref's edit & commit
when your EditText's text changed, although it's a bad design...
You need a Text change listener
EditText.addTextChangedListener(new TextWatcher()
{
#Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{}
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{}
#Override
public void afterTextChanged(Editable s)
{}
});

How do you save the data of an int, and then edit the number onclick of a button?

I am trying to have it so when you click one of the answeers (Q1A1 or Q1A2) it will add a number of points to the testScore int so I can then later call that in a later class so the score they got would be posted there. Thanks to anyone who helps in advance!
here's my code,
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
public class Test extends Activity implements OnClickListener
{
TextView Q1A1;
TextView Q1A2;
TextView test;
public static final String PREFS_NAME = "MyPrefsFile";
public static final int testScore = 0;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
Q1A1 = (TextView) findViewById(R.id.Q1A1);
Q1A2 = (TextView) findViewById(R.id.Q1A2);
Q1A1.setOnClickListener(this);
Q1A2.setOnClickListener(this);
test = (TextView) findViewById(R.id.test);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
test.setText(settings.getString("YourScore", "No Score"));
}
public void onClick(View v)
{
switch(v.getId())
{
case R.id.Q1A1:
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("YourScore", (testScore + 10));
editor.commit();
//Intent FinalScore = new Intent(this, FinalScore.class);
//startActivity(FinalScore);
break;
case R.id.Q1A2:
break;
}
}
}
thanks for the help
You are are saving your score as an int but calling it as a string.
Change
test.setText(settings.getString("YourScore" , "No Score"));
To
test.setText(""+settings.getInt("YourScore" , 0));

Categories

Resources