构造函数ArrayAdapter<串GT;未定义函数、未定义、LT、ArrayAdapter

由网友(听弦断)分享简介:我有一个方法, initializeViews ,其中遇到的 ArrayAdapter构造未定义错误在文件的最后一行。 该方法位于 F1Fragment ,它扩展了 MainFragment 。 MainFragment 然后连接到活动。 难道我们不能给出一个片段在 ArrayAdapter&LT上下文;串>...

我有一个方法, initializeViews ,其中遇到的 ArrayAdapter构造未定义错误在文件的最后一行。

该方法位于 F1Fragment ,它扩展了 MainFragment MainFragment 然后连接到活动

难道我们不能给出一个片段 ArrayAdapter&LT上下文;串> 构造?我是新来的Andr​​oid系统。请指正。先谢谢了。

 私人无效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 函数

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.

阅读全文

相关推荐

最新文章