0

I am using map fragment to show the user current location on maps.. and also the spinner at the top bar..Refer below image:

enter image description here

Here all of the view is in the tab activity. Now whenever I clicked on spinner to expand, it crashes the app and shows the error as:

       android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@40643d88 is not valid; is your activity running?

Refer the below code for populating spinner with items:

     ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getParent(),
            android.R.layout.simple_spinner_item, cat);
     dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner_cat.setAdapter(dataAdapter);

Please suggest..Please note that these views are in the tabs

Kanika
  • 10,648
  • 18
  • 61
  • 81

2 Answers2

0

May be the issue is with the context try passing getActivity() instead of getParent()

in your adapter constructor

cafebabe1991
  • 4,928
  • 2
  • 34
  • 42
0

I had this same problem, when adding a fragment to a view (not a Mapfragment, just a custom one), and the answer for me was to pass in getApplicationContext(), but I had to do it through a separate method after instantiating the fragment, since it was requiring the use of a Bundle.

The following is also necessary when inflating the view, using the context passed in above:

View v = inflater.from(context).inflate(R.layout.layout_name, ViewGroup container, T/F);

rather than just

View v = inflater.inflate(R.layout.layout_name, ViewGroup container, T/F);

Hope this helps.

craned
  • 2,991
  • 2
  • 34
  • 38