njnjnj
njnjnj

Reputation: 984

Using arraylist<string> for setting adapter for autocomplete textview in android

In my android app, I have an arraylist containing server data received from server. I need to use this arraylist in the arrayadapter for using it in an autocomplete textview for showing suggestions while the user types the characters. I have seen many tutorials using string array in the arrayadapter and setting it for auto complete textview. But haven't found any solution using arraylist. Please help me out..

EDIT:

this is the code which I have used:

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);

Adding loc is showing me an error in logcat as shown here: The constructor ArrayAdapter(CommunityFragment, int, ArrayList) is undefined

Upvotes: 2

Views: 4784

Answers (1)

Autumn
Autumn

Reputation: 91

From the ArrayAdapter documentation,

public ArrayAdapter (**Context context**, int resource, List<T> objects)

From your error, it looks like you're passing in a Fragment reference, which is not a context.

Try

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,loc);

Upvotes: 6

Related Questions