java - Android Spinner issue - The constructor ArrayAdapter<String>(NewSRO, int, String[]) is undefined -
i having hell of time spinner under pageradapter. please take @ provide suggestions might have. stump, might late @ night. tried wrap code separate class , call class no success. next figured need add getactivity()
fragment, having issues.
public class newsro extends pageradapter { //---return total number of pages--- public int getcount() { return 3; } public object instantiateitem(view collection, int position) { layoutinflater inflater = (layoutinflater) collection.getcontext() .getsystemservice(context.layout_inflater_service); int resid = 0; view view = null; // setting view variable null value switch (position) { case 0: resid = r.layout.new_client_1; view = inflater.inflate(resid, null); // inflating view attach spinner data final spinner s1_clients; final string[] clients = { "client1", "client2", "3", "4" }; //---spinner view--- s1_clients = (spinner) view.findviewbyid(r.id.spinner_client_select); spinneradapter new_adapter = new arrayadapter<string>( newsro.this, android.r.layout.simple_spinner_item, clients); s1_clients.setadapter(new_adapter); s1_clients.setonitemselectedlistener(new onitemselectedlistener() { public void onitemselected(adapterview<?> arg0, view arg1, int arg2, long arg3) { int index = s1_clients.getselecteditemposition(); toast.maketext(null, "you have selected item : " + clients[index], toast.length_short).show(); } public void onnothingselected(adapterview<?> arg0) { } }); break; case 1: resid = r.layout.new_client_1; break; case 2: resid = r.layout.new_client_1; break; } //view view = inflater.inflate(resid, null); ((viewpager) collection).addview(view, 0); return view; } @override public void destroyitem(view arg0, int arg1, object arg2) { ((viewpager) arg0).removeview((view) arg2); } @override public boolean isviewfromobject(view arg0, object arg1) { return arg0 == ((view) arg1); } @override public parcelable savestate() { return null; } }
at first seemed adding collection.getcontext() right direction. albeit, caused me stop paying attention inflated view problem. each case statement needed view inflate, without application crash.
basically needed add following each case statement:
view = inflater.inflate(resid, null);
then needed modify spinneradapter view.getcontext() :
spinneradapter new_adapter = new arrayadapter<string>( view.getcontext(), android.r.layout.simple_spinner_item, clients);
i hope else viewpager great way enhance user interface.
cheers, brandy lee camacho
Comments
Post a Comment