I would like to create a customized popup dialog which contains a spinner. The dialog needs to be launched from an Adapter class, below is my code:
Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.myPopup);
Spinner spinner = (Spinner)dialog.findViewById(R.id.spinner);
ArrayAdapter<String> arrayadapter = new ArrayAdapter<String>(mContext, 0);
arrayadapter.add("AddSomeStrings");
spinner.setAdapter(arrayadapter);
dialog.show();
This code is executed fine, but sometime after the “show()”, I see an exception: Resources$NotFoundException. The last item in the callstack is Resources.loadXmlResourceParser. If I don’t assign the spinner using findViewById, but instead assign it via spinner = new Spinner(dialog.getContext()), then I don’t get the error (but then of course I cannot see my dialog).
myPopup layout contains:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
>
<Spinner
android:id="@+id/spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="true"
android:prompt="@string/group_prompt"
/>
</LinearLayout>
Any thoughts what I am doing wrong? thanks!
Your using the array adapter with Constructor Context and TextView ID, but your just passing it 0 as the text view resource id.
See the API here : ArrayAdapter
Try:
or other resource of you choice