Possible to inflate android spinner layout extended by ActionBarSherlock? -
is possible inflate textview
@android:id/text1
? don't want create own layout, little modified text.
here code:
first, created variable store data
private list<hashmap<string, string>> datacities = new arraylist<hashmap<string, string>>(); //hashmap keys , values //id - 0 //name - default
second, created custom adapter in oncreate
@override protected void oncreate(bundle savedinstancestate) { //... spinner citiesspinner = (spinner) findviewbyid(r.id.city_sp); citiesadapter = new customarrayadapter(this, r.layout.sherlock_spinner_item, datacities); citiesspinner.setadapter(citiesadapter); }
third, created listener. works after calling notifydatasetchanged nothing happens. why?
@override public void onrequestjsonresponded(requesttype type, jsonarray array) { //my enum type switch (type) { case cities: //returns hashmap in arraylist, arraylist<hashmap<string,string>> ... datacities = parsejsonarray(array); log.d(tag, "end of parsing"); citiesadapter.notifydatasetchanged(); break; case mark: //... break; case model: break; } }
here custom arrayadapter
private class customarrayadapter extends arrayadapter<hashmap<string, string>> { public customarrayadapter(context context, int textviewresourceid, list<hashmap<string, string>> objects) { super(context, textviewresourceid, objects); } @override public view getview(int position, view convertview, viewgroup parent) { layoutinflater layoutinflater = layoutinflater.from(getcontext()); view v = layoutinflater.inflate(r.layout.sherlock_spinner_item, null); textview tv = (textview)v.findviewbyid(android.r.id.text1); tv.settext(getitem(position).get("name")); return v; } }
could tell me why blank spinner data? (spinner empty). , how modified text without creating new layout? use sherlock spinner item layout. please help.
simple, list in adapter not same list retrieved:
//in here update activity's list returned values datacities = parsejsonarray(array); log.d(tag, "end of parsing"); //but adapter using original value of datacities (new arraylist<hashmap<string, string>>() ) citiesadapter.notifydatasetchanged();
since adapter depends on arrayadapter, easiest solution might create new adapter when data received.
Comments
Post a Comment