0

I have a problem that is bugging me. I created a string array in strings.xmlwhich is called bookmark_titles. I want to use it for my alert dialog and populate a list using them, however I can't see name of my array in R.array, it has only those that built in android eg PhoneTypes. How do I reference my array ?

strings.xml

<string name="app_name">Dialogs</string>
<string name="action_settings">Settings</string>

<string-array name="bookmark_titles">
    <item>Google</item>
    <item>Bing</item>
    <item>Gmail</item>
</string-array>

</resources>

FireMissilesDialogFragment

public class FireMissilesDialogFragment extends DialogFragment{

public Dialog onCreateDialog(Bundle savedInstanceState) {
     AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setTitle("Books are :");
               .setItems(R.array., new DialogInterface.OnClickListener() {   ---> can't see reference here
                   public void onClick(DialogInterface dialog, int which) {
                   // The 'which' argument contains the index position
                   // of the selected item
               }
        });
        return builder.create();

    }
4
  • 1
    Did you try a clean/rebuild? Can't see a reason it wouldn't show up as R.array.bookmark_titles. Commented Jul 24, 2013 at 11:05
  • 1
    refer it like R.array.bookmark_titles. more info @ developer.android.com/guide/topics/ui/dialogs.html. Also check this developer.android.com/guide/topics/resources/…. Commented Jul 24, 2013 at 11:06
  • @Joachim Isaksson yes I cleaned the project, same issue Commented Jul 24, 2013 at 11:10
  • @Frugo try removing ; from builder.setTitle("Books are :"). Commented Jul 24, 2013 at 11:15

3 Answers 3

1

try "array":

<array name="bookmark_titles">
<item>Google</item>
<item>Bing</item>
</array>
Sign up to request clarification or add additional context in comments.

Comments

1

Documentation for setItems() states that:

This should be an array type i.e. R.array.foo

Use an array instead of string-array:

<string name="bookmark_google">Google</string>
<string name="bookmark_bing">Bing</string>
<string name="bookmark_yahoo">Yahoo</string>

<array name="pref_values_sort_list">
    <item>@string/bookmark_google</item>
    <item>@string/bookmark_bing</item>
    <item>@string/bookmark_yahoo</item>
</array>

1 Comment

i don't think that's an issue. developer.android.com/guide/topics/resources/…. i just tried it out with string array works for me.
0

Solved the issue.

I had to remove import.android.R, after it, it worked ! Thanks guys

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.