There are three different spinners that are placed in the dialogFragment. These spinners have their own custom markup and the data is transferred to them from the fragment. The transfer is done using the bundle in the snippet:

FullScreenDialog dialog = new FullScreenDialog(); Bundle bundle = new Bundle(); bundle.putStringArrayList("sp1_1", (ArrayList<String>) title1); bundle.putStringArrayList("sp1_2", (ArrayList<String>) count1); bundle.putStringArrayList("id1", (ArrayList<String>) id1); bundle.putStringArrayList("sp2_1", (ArrayList<String>) title2); bundle.putStringArrayList("sp2_2", (ArrayList<String>) count2); bundle.putStringArrayList("id2", (ArrayList<String>) id2); bundle.putStringArrayList("sp3_1", (ArrayList<String>) title3); bundle.putStringArrayList("sp3_2", (ArrayList<String>) count3); bundle.putIntegerArrayList("id3", (ArrayList<Integer>) id3); bundle.putSerializable("filter_data", data); dialog.setArguments(bundle); 

and here is how the data is obtained in the dialogue:

 Bundle bundle = getArguments(); title1 = Objects.requireNonNull(bundle).getStringArrayList("sp1_1"); count1 = Objects.requireNonNull(bundle).getStringArrayList("sp1_2"); title2 = Objects.requireNonNull(bundle).getStringArrayList("sp2_1"); count2 = Objects.requireNonNull(bundle).getStringArrayList("sp2_2"); title3 = Objects.requireNonNull(bundle).getStringArrayList("sp3_1"); count3 = Objects.requireNonNull(bundle).getStringArrayList("sp3_2"); ids1 = bundle.getStringArrayList("id1"); ids2 = bundle.getStringArrayList("id2"); ids3 = bundle.getStringArrayList("id3"); data = (HashMap<String, String>) bundle.getSerializable("filter_data"); 

Then I have a condition in the dialog, if the data variable is not empty, then you need to set a certain item in the spinner, this condition looks like this:

 if (!data.isEmpty()) { spinner1.setSelection(ids1.indexOf(data.get("prof")) + 1); spinner2.setSelection(ids2.indexOf(data.get("location")) + 1); spinner3.setSelection(ids3.indexOf(data.get("employer"))+2); } 

everything seems to work well, but for spinner3 reason in spinner3 you need to add +2 elements to get to the desired item instead of +1 as in the previous two, and if you look at the logs, then the index of the element that came from the fragment is -1. In general, in the spinners, I add +1 because I still have a default inscription there that needs to be bypassed. I have already walked through the debugger through the whole dialogue and all the variables - everything comes right, but why is there one situation in two spinners and another in the third? I can not understand what is happening there.

UPDATE

I just checked it, and adding +2 still didn't solve the problem, it turns out that I don’t find such an element in the hashmap, although it is there and other spinners find their elements.

    2 answers 2

    From the oddities for your description I see the following

     bundle.putStringArrayList("id1", (ArrayList<String>) id1); bundle.putStringArrayList("id2", (ArrayList<String>) id2); bundle.putIntegerArrayList("id3", (ArrayList<Integer>) id3); 

    putIntegerArrayList and ArrayList<Integer> on id3

    • changed, but nothing has changed - Andrew Goroshko February
    • all the same, it turns out that my list does not have elements from hashMap in itself, although this is strange at all - Andrew Goroshko February

    Solved the problem by crushing a crutch. So it turns out that from the fragment I pass an array of numbers to the dialogue and also transfer a hashMap in which there is a number that must be present in the array. So it turns out that I could not find the number in the transferred array and send the index of this number to the spinner. Here is what I did in the end:

     spinner3.setSelection(ids3.indexOf(Integer.parseInt(data.get("employer"))) + 1); 

    I agree that this is probably very wrong, but in the end it works as it should. Maybe someone will help.