使用arraylist <string>在android中为自动完成的textview设置适配器

njn*_*jnj 2 arrays android arraylist autocompletetextview

在我的Android应用程序中,我有一个arraylist包含从服务器接收的服务器数据。我需要在arrayadapter中使用此arraylist,以便在自动完成的文本视图中使用它,以便在用户键入字符时显示建议。我看过许多教程,在arrayadapter中使用字符串数组并将其设置为自动完成textview。但是还没有找到任何使用arraylist的解决方案。请帮帮我..

编辑:

这是我使用的代码:

View rootView = inflater.inflate(R.layout.fragment_community, container, false);
    actv1=(AutoCompleteTextView)rootView.findViewById(R.id.autoCompleteTextView1);
    actv2=(AutoCompleteTextView)rootView.findViewById(R.id.autoCompleteTextView2);
    loc=new ArrayList<String>();
    SplashScreen ss = new SplashScreen();
    loc=ss.loc;


    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,loc);
Run Code Online (Sandbox Code Playgroud)

添加loc向我显示logcat中的错误,如下所示:构造函数ArrayAdapter(CommunityFragment,int,ArrayList)未定义

小智 6

ArrayAdapter文档中

public ArrayAdapter (**Context context**, int resource, List<T> objects)
Run Code Online (Sandbox Code Playgroud)

从您的错误看来,您正在传递的不是上下文的Fragment引用。

尝试

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,loc);
Run Code Online (Sandbox Code Playgroud)