android - Error - No suitable constructor found for ArrayAdapter -


i have code in 1 of tabs of android application :-

import android.os.bundle; import android.support.v4.app.fragment; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import android.widget.arrayadapter; import android.widget.autocompletetextview;  public class placeholderfragment extends fragment {     /**      * fragment argument representing section number      * fragment.      */     private static final string arg_section_number = "section_number";      /**      * returns new instance of fragment given section      * number.      */     public static placeholderfragment newinstance(int sectionnumber) {         placeholderfragment fragment = new placeholderfragment();         bundle args = new bundle();         args.putint(arg_section_number, sectionnumber);         fragment.setarguments(args);         return fragment;     }      public placeholderfragment() {     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {         view rootview = inflater.inflate(r.layout.fragment_main, container, false);         string str[]={"arun","mathev","vishnu","vishal","arjun",                 "arul","balaji","babu","boopathy","godwin","nagaraj"};          autocompletetextview t1 = (autocompletetextview)                 rootview.findviewbyid(r.id.autocompletetextview1);          arrayadapter<string> adp=new arrayadapter<string>(this,                 android.r.layout.simple_dropdown_item_1line,str);          t1.setthreshold(1);         t1.setadapter(adp);         return rootview; 

and following line underlined in red hence causing error

(this,android.r.layout.simple_dropdown_item_1line,str)

i tried edit problem still remains

here default contructor of arrayadapter using , should pass context first parameter

arrayadapter (context context, int resource, list objects)

so change

arrayadapter<string> adp=new arrayadapter<string>(this,                 android.r.layout.simple_dropdown_item_1line,str); 

to

arrayadapter<string> adp=new arrayadapter<string>(getactivity(),                 android.r.layout.simple_dropdown_item_1line,str); 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -