This code is not working for me........i'm trying to use Shared
preferences to store long values.....the code is correct and is
launching successfully when i switch from long to int values....please
help
package d.preferencesdemo1;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class preferencesdemo1 extends Activity {
/** Called when the activity is first created. */
EditText t;
long mobileno;
TextView text;
SharedPreferences app_preferences;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get the app's shared preferences
app_preferences =
PreferenceManager.getDefaultSharedPreferences(this);
mobileno = app_preferences.getLong("mobileno",9028252169L);
// Update the TextView
text = (TextView) findViewById(R.id.text);
text.setText("The default mobile number is " + mobileno +
".");
// Increment the mobileno
// SharedPreferences.Editor editor = app_preferences.edit();
// editor.putlong("mobileno", ++mobileno);
//editor.commit(); // Very important
t = (EditText) findViewById(R.id.EditText01);
Button b2 = (Button) findViewById(R.id.Button01);
t.setText("");
b2.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
try {
// Increment the mobileno
SharedPreferences.Editor editor =
app_preferences.edit();
long tv =
Long.parseLong(t.getText().toString());
mobileno=tv;
editor.putLong("mobileno", mobileno);
editor.commit(); // Very important
text.setText("The default mobile number is "
+ mobileno + ".");
}
catch (Exception e) {
}
}
});
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en