eltos / SimpleDialogFragments

An Android library to create dialogs with ease and handle user interaction reliably, using fragments and material design.
Apache License 2.0
119 stars 17 forks source link

String Array in strings.xml #2

Closed kaplanerkan closed 7 years ago

kaplanerkan commented 7 years ago

Hello,

I love your plugins and will add in my app but can you please add a new features?

I define my Arrays in strings.xml

    <string-array name="country_arrays">
        <item>ABC</item>
        <item>A</item>
        <item>B</item>
        <item>C</item>
        <item>D</item>
.............
...............

and use like a spinner in your sample app (onSingleClick)

    // That work OK
   //int[] data = new int[]{R.string.choice_A, R.string.choice_B, R.string.choice_C, R.string.choice_D, R.string.choice_E, R.string.choice_F, R.string.choice_G, R.string.choice_H, R.string.choice_I, R.string.choice_K, R.string.choice_L, R.string.choice_M};

        int[] data = new int[]{R.array.country_arrays};   // <==  DONT WORK HERE
        Bundle extras = new Bundle();
        extras.putIntArray("labels", data);

        SimpleListDialog.build()
                .title(R.string.select_one)
                .choiceMode(SimpleListDialog.SINGLE_CHOICE) // _DIRECT
                .choiceMin(1)
                .items(getBaseContext(), data)
                .extra(extras)
                .show(MainActivity.this, LIST_DIALOG);

and crash;

   Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x7f0d0002
                      at android.content.res.Resources.getText(Resources.java:1442)
                      at android.content.res.Resources.getString(Resources.java:1536)
                      at android.content.Context.getString(Context.java:383)
                      at eltos.simpledialogfragment.list.SimpleListDialog.items(SimpleListDialog.java:63)
                      at eltos.simpledialogfragments.MainActivity.onSingleClick(MainActivity.java:161)

Can you please add this features an we can user your plugins with R.array.xxxx ???

Thanks erkan kaplan

eltos commented 7 years ago

Excellent idea, I will add a method for string arrays in the next release.

Meanwhile you can use the following:

.items(getResources().getStringArray(R.array.xxxx))
kaplanerkan commented 7 years ago

danke dir :-)

kaplanerkan commented 7 years ago

Hello Eltos,

how can i download v 1.2?

thanks

kaplanerkan commented 7 years ago

sorry, i found it into MASTER-Branch.

It work now:

  Bundle extras = new Bundle();
        //extras.putIntArray("labels", data);
        extras.putStringArray("labels", getResources().getStringArray(R.array.country_arrays));

        SimpleListDialog.build()
                .title(R.string.select_one)
                .choiceMode(SimpleListDialog.SINGLE_CHOICE) // _DIRECT
                .choiceMin(1)
                .items(getResources().getStringArray(R.array.country_arrays))
                .extra(extras)
                .show(MainActivity.this, LIST_DIALOG);

and choice-Result;

  case LIST_DIALOG:
                    ArrayList<Integer> pos = extras.getIntegerArrayList(SimpleListDialog.SELECTED_POSITIONS);
                    //int[] label = extras.getIntArray("labels");
                    String[] myArrays_str= extras.getStringArray("labels");
                    int position = pos.get(0);

                    System.out.println("AUSWAHL " + myArrays_str[position]);
//