无法解析构造函数ArrayAdapter(Listview,fragment) [英] Cannot resolve constructor ArrayAdapter (Listview , fragment )

查看:106
本文介绍了无法解析构造函数ArrayAdapter(Listview,fragment)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在片段中加载一个列表视图,适配器的问题是错误-Cannot resolve constructor ArrayAdapter.

I want to load a listview in my fragment and the problem with the adapter is the error - Cannot resolve constructor ArrayAdapter.

这是我班上的onCreateView方法:

 public class AndroidGUIModifier implements IMyComponentGUIModifier, IFragmentEvents {

    @Override
    public void onCreateView() {
        tv1 = (TextView) fragment.findViewById("xtv1");
        tv2 = (TextView) fragment.findViewById("xtv2");
        lv=(ListView) fragment.findViewById("xdevices") ;

        mydevices = new ArrayList<String>();

        ArrayAdapter<String> adapter = new ArrayAdapter<String>(AndroidGUIModifier.this,android.R.layout.simple_list_item_1,mydevices);// the problem here : Cannot resolve constructor ArrayAdapter

        lv.setAdapter(adapter);
    }

}

推荐答案

从片段中获取Context并将其传递给ArrayAdapter:

Obtain the Context from the fragment and just pass it to the ArrayAdapter :

ArrayAdapter<String> adapter = new ArrayAdapter<String>(fragment.getContext(), android.R.layout.simple_list_item_1, mydevices);

这篇关于无法解析构造函数ArrayAdapter(Listview,fragment)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆