构造函数ArrayAdapter&LT;串GT;未定义 [英] The constructor ArrayAdapter<string> is undefined
本文介绍了构造函数ArrayAdapter&LT;串GT;未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个方法, initializeViews
,其中遇到的 ArrayAdapter构造未定义
错误在文件的最后一行。
该方法位于 F1Fragment
,它扩展了 MainFragment
。 MainFragment
然后连接到活动
。
难道我们不能给出一个片段
在 ArrayAdapter&LT上下文;串&GT;
构造?我是新来的Android系统。请指正。先谢谢了。
私人无效initializeViews(RelativeLayout的contentLayout){
leaguesListView =(ListView控件)contentLayout.findViewById(R.id.leaguesListView);
progressLinear =(的LinearLayout)contentLayout.findViewById(R.id.progressLeagues);
值=新的String [] {RedBullRacing,迈凯轮,莲花,
印度力量车队,HRT,法拉利};
适配器=新ArrayAdapter&LT;串GT;(F1Fragment.this,android.R.layout.simple_list_item_1,android.R.id.text1,价值观);
}
解决方案
修改 F1Fragment.this
到 getActivity()
。在片段
不是上下文
。
I have a method, initializeViews
, which encounters an ArrayAdapter constructor undefined
error in its last line.
The method is located in F1Fragment
, which extends MainFragment
. MainFragment
is then attached to an Activity
.
Can we not give the context of a Fragment
in the ArrayAdapter<string>
constructor? I am new to Android. Please correct me. Thanks in advance.
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);
}
解决方案
Change F1Fragment.this
to getActivity()
. The Fragment
is not a Context
.
这篇关于构造函数ArrayAdapter&LT;串GT;未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文