2011-07-21 42 views
2

我正在製作一個應用程序,而且我正面臨一個問題。TabBars中的Android微調問題

我正在使用選項卡欄,並在我的一個選項卡欄中使用微調框。

它加載完美,但是當我點擊它。它給我:

android.view.WindowManager$BadTokenException: Unable to add window -- token [email protected] is not valid; is your activity running? 

這個錯誤。

我用下面的代碼片段

 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); 

此代碼工作正常,當我使用單獨的活動不是標籤欄。但在標籤欄,它給了我上面的錯誤異常,當我點擊微調打開列表。

請指引我感謝一大堆

+0

你使用ActivityGroup?由於錯誤,你似乎傳遞了錯誤的上下文。 –

+0

請..任何人都可以幫助我atleast :( – Shah

+0

是ia m使用活動組 – Shah

回答

4

餘米這個 的問題是與我的佈局

setContentView(R.layout.age) 

取而代之的是我用佈局氣筒按以下步驟進行:

View viewToLoad = LayoutInflater.from(this.getParent()).inflate(R.layout.country, null); 
     this.setContentView(viewToLoad); 

然後叫Spinner n Bingooo!它的作品剛完美

謝謝你們所有人.. :)