I have a problem that is bugging me. I created a string array in strings.xml
which 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();
}
try "array":
<array name="bookmark_titles">
<item>Google</item>
<item>Bing</item>
</array>
Documentation for setItems()
states that:
This should be an array type ie 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>
Solved the issue.
I had to remove import.android.R, after it, it worked ! Thanks guys
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.