How to add a Boolean Array in Shared preferences in Android

后端 未结 3 911
梦如初夏
梦如初夏 2020-12-07 03:23

I want to store a Boolean array in Shared preferences ,and i want to access the array elements later. Can anybody help me ?.Thanks in advnc.

3条回答
  •  误落风尘
    2020-12-07 04:08

    Store ArrayList Globally in sharedpreferences using checkbox.

     public boolean saveCheckboxarray(Context mContext, ArrayList array) {
    
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
        SharedPreferences.Editor editor = prefs.edit();
        editor.putInt(CHECKBOXARRAY, array.size());
    
        for(int i=0;i

    Load ArrayList Globally in sharedpreferences Status.

    public ArrayList getCheckboxarray(Context mContext) {
    
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
        int size = prefs.getInt(CHECKBOXARRAY, 0);
        ArrayList getArray=new ArrayList();
        for(int i=0;i

提交回复
热议问题