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
Post a Comment