2012-08-29 108 views
7

我有一個方法initializeViews,它在最後一行遇到ArrayAdapter constructor undefined錯誤構造函數ArrayAdapter <string>未定義

該方法位於F1Fragment,其延伸MainFragmentMainFragment然後附加到Activity

我們不能在ArrayAdapter<string>構造函數中給出Fragment的上下文嗎?我是Android新手。請糾正我。提前致謝。

private void initializeViews(RelativeLayout contentLayout) { 
    leaguesListView = (ListView) contentLayout.findViewById (R.id.leaguesListView); 
    progressLinear = (LinearLayout) contentLayout.findViewById (R.id.progressLeagues); 
    values= new String[] { "RedBullRacing", "McLaren", "Lotus", 
     "ForceIndia", "HRT", "Ferrari" }; 
    adapter= new ArrayAdapter<String>(F1Fragment.this, android.R.layout.simple_list_item_1, android.R.id.text1, values); 
} 

回答

39

變化F1Fragment.this變爲getActivity()Fragment不是Context

相關問題