sharedpreferences

Android add string to shared preferences

杀马特。学长 韩版系。学妹 提交于 2021-02-20 04:17:41
问题 my task is to write simple application: 1. user writes a String in a Text field and save it to SharedPreferences (his note) saveButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { text = textEtxt.getText().toString(); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(textEtxt.getWindowToken(), 0); // save to ShPr sharedPreference.save(context, text); Toast.makeText(context,

Storing an int value using Shared preferences

自作多情 提交于 2021-02-18 18:52:57
问题 I have an int "flag" variable , which will have two possible int values , 0 & 1. Main theme of the app here is : Ask user yes or no? If user selects YES, assign int=1. else if Selects No, assign int=0; I am achieving this using: public static int flag; @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.flag0: flag=0; System.err.println("Flag : " + flag); break; case R.id.flag1: flag=1; System.err.println("Flag : " + flag); break; default:

Saving Data from ListView using SharedPreferences

点点圈 提交于 2021-02-18 13:51:37
问题 i tried searching for an answer but could not find what i was looking for: this was my first try at saving data/using SharedPreferences so i wasnt quite sure of what i was doing. The main point was so that after a user inputs something in the EditText, it populates the ListView. But i also want it so that when this is carried out, the app also saves the string so that I can use LoadPreferences to have it when a user re-enters the app. This does not happen though the code: public class

How To Retrieve RadioPreference, CheckPreference values in Preferences in Flutter

让人想犯罪 __ 提交于 2021-02-17 05:52:05
问题 I am having a hard time retrieving the user preference in multiple RadioPreference in a flutter project using the Preferences library https://pub.dev/packages/preferences#. I know how to use SharedPreferences in Flutter but after following the example in the preference page, I can't seems to retrieve the actual user selection. For example PreferenceDialogLink( 'Android\'s "ListPreference"', dialog: PreferenceDialog( [ RadioPreference( 'Select me!', 'select_1', 'android_listpref_selected'),

How can I save the state of the checkboxes in a custom listview using sharedpreferences?

北慕城南 提交于 2021-02-11 17:24:08
问题 I have checkboxes in my custom listview, I'm using a boolean array to save the state of these checkboxes. I want to make the state of checkboxes persistent through out the lifetime of the app.I know that this can be achieved through sharedpreferences, but I don't exactly know how this can be done. 回答1: I know that this can be achieved through sharedpreferences, but I don't exactly know how this can be done. There is no option to push serializable objects into sharedpreferences. Because of

How to save List<List<String>> with SharedPreferences in Flutter

拜拜、爱过 提交于 2021-02-10 14:53:17
问题 I am trying to save a List of List but I don't know how to do that. So I have List<List> _randList = new List(); 回答1: See, there is no way that we can use Shared Preferences in order store List<List<String>> . However, we can always use a workaround. Since, we already that we can store the List<String> only in the Shared Preferences, it is best to store the nested lists in the form of String , like below List<String> _arr = ["['a', 'b', 'c'], ['d', 'e', 'f']"]; In this way, you will be having

How to store theme on SharedPreference in Android

与世无争的帅哥 提交于 2021-02-10 11:53:55
问题 I'm trying to save my theme by using sharedpreference, so I used this code: My SettingsActivity: public class SettingsActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ThemeUtils.onActivityCreateSetTheme(this); setContentView(R.layout.settings); findViewById(R.id.blackbutton).setOnClickListener(this); findViewById(R.id.bluebutton).setOnClickListener(this); findViewById(R.id.pinkbutton)

How to store theme on SharedPreference in Android

こ雲淡風輕ζ 提交于 2021-02-10 11:51:20
问题 I'm trying to save my theme by using sharedpreference, so I used this code: My SettingsActivity: public class SettingsActivity extends Activity implements OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ThemeUtils.onActivityCreateSetTheme(this); setContentView(R.layout.settings); findViewById(R.id.blackbutton).setOnClickListener(this); findViewById(R.id.bluebutton).setOnClickListener(this); findViewById(R.id.pinkbutton)

How Use shared preference with injectable and get_it in flutter?

江枫思渺然 提交于 2021-02-09 08:59:12
问题 im using injectable and get_it package in flutter i have a shared preference class : @LazySingleton() class SharedPref { final String _token = 'token'; SharedPreferences _pref; SharedPref(this._pref); Future<String> getToken() async { return _pref.getString(_token) ?? ''; } Future<void> setToken(String token) async { await _pref.setString(_token, token); } } this class inject as LazySingleton and i have a module for inject the shared preference : @module abstract class InjectableModule {

SharedPreferences to a custom path - Android

北战南征 提交于 2021-02-08 10:24:06
问题 I want to keep my SharedPreferences xml in a different place where default path is the application package. Can we set a custom path for android SharedPreferences and use it while it is in that path ? 回答1: You can create a adapter to get preferences. First, create an interface IPreferences (Not necessary but make your life easier if you want to change it back or change to another method): public interface IPreferences { boolean contains(String key); int getInt(String key, int defValue);