Problem in Android Spinner inside the Tabbars
I am making an application and i am facing a problem.
I am using Tab bars and in one of my Tab bar i am using S开发者_如何学Cpinner.
It loads Perfectly but when i click on it. it gives me:
android.view.WindowManager$BadTokenException: Unable to add window -- token android.app.LocalActivityManager$LocalActivityRecord@44647ef8 is not valid; is your activity running?
This error.
i am using the following code snippet
ArrayList<String> ageList;
Spinner age;
age = (Spinner) findViewById(R.id.country);
ageList = new ArrayList<String>();
ageList.add("10-20");
ageList.add("21-35");
ageList.add("36-60");
ageList.add("61-100");
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, ageList); //array you are populating
adapter2.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
age.setAdapter(adapter2);
age.setSelection(0, true);
This code work fine when i am using seperate activity not the tab bars. but in tab bars it gives me the above error exception when i click on the spinner to open a list.
Please guide me Thanks a bunch
I m done with this the problem was with my layout
setContentView(R.layout.age)
Instead of this i used Layout Inflator as below:
View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.country, null);
this.setContentView(viewToLoad);
and then called the Spinner n Bingooo! It works Just Perfect
Thanks all of you.. :)
精彩评论