How can I separate the items of a sharedPreferences into an Array?

1

I'm having a question, I've made a checkbox on items in a listview that when marked are stored as SharedPreferences. Then I created a button (Favorites) to access the items marked by the checkbox, but the checked items go to Favorites I re-created a new listview to receive the items, but several items only come with an item in the Favorites listview, the.

Follow my code:

SharedPreferences sharedPreferences = getSharedPreferences("arquivoPreferencia", MODE_PRIVATE);

       String fraseR = String.valueOf(sharedPreferences.getAll());


            // CRIANDO O ARRAY

            final String[] frasesFavoritoArray =
                    {
                            fraseR
                    };

I think the problem is exactly in the Array that is getting all the items in the 'R' phrase, but I would not know how to separate them.

Is there any solution for this?

Thank you very much.

    
asked by anonymous 02.06.2017 / 21:52

1 answer

2

Change your code to this:

SharedPreferences sharedPreferences = getSharedPreferences("arquivoPreferencia", MODE_PRIVATE);
List<String> frasesFavoritoArray = new Arraylist<>();
Map<String, ?> allEntries = sharedPreferences.getAll();
for (Map.Entry<String, ?> entry : allEntries.entrySet()) {    
   frasesFavoritoArray.add(entry.getValue().toString());
}
    
03.06.2017 / 04:02