Skip to content Skip to sidebar Skip to footer

How Can I Create A Spinner Within A Fragment?

I'm trying to create a spinner in a fragment but while making the spinner dialog it fails to recognize the fragment java class using '.this'. I'm not sure what I should be doing in

Solution 1:

Replace Add.this with getActivity().

It's hard to say for sure exactly what the problem is (since I don't know how SpinnerDialog is implemented), but chances are very good that the constructor's first argument is a Context. Fragments do not implement Context, but Activitys do. So instead of passing in your Fragment instance, pass in its containing Activity.

Solution 2:

Add.this is context parameter.

If Add.class is a fragment, use getActivity() when passing the context parameter.

But if Add.class is an activity, is Add.this instead.

Post a Comment for "How Can I Create A Spinner Within A Fragment?"