由网友(听弦断)分享简介:我有一个方法, initializeViews ,其中遇到的 ArrayAdapter构造未定义错误在文件的最后一行。 该方法位于 F1Fragment ,它扩展了 MainFragment 。 MainFragment 然后连接到活动。 难道我们不能给出一个片段在 ArrayAdapter&LT上下文;串>...![PHP源码阅读 array pop 和 array shift 函数](https://p.xsw88.cn/allimgs/daicuo/20230908/284.png)
我有一个方法, initializeViews
,其中遇到的 ArrayAdapter构造未定义
错误在文件的最后一行。
该方法位于 F1Fragment
,它扩展了 MainFragment
。 MainFragment
然后连接到活动
。
难道我们不能给出一个片段
在 ArrayAdapter&LT上下文;串>
构造?我是新来的Android系统。请指正。先谢谢了。
私人无效initializeViews(RelativeLayout的contentLayout){ leaguesListView =(ListView控件)contentLayout.findViewById(R.id.leaguesListView); progressLinear =(的LinearLayout)contentLayout.findViewById(R.id.progressLeagues); 值=新的String [] {RedBullRacing,迈凯轮,莲花, 印度力量车队,HRT,法拉利}; 适配器=新ArrayAdapter<串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.
![PHP源码阅读 array pop 和 array shift 函数](https://p.xsw88.cn/allimgs/daicuo/20230908/284.png)
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
.
相关推荐
最新文章