android - Spinner 2 data not populating properly -
i trying load spinner2 data based on spinner1 item selection. spinner1 loads without issues. have got 2 categories in spinner1. before selecting value on spinner1, spinner2 loaded second categories values.
edit: 1 thing realized now. have got 2 values in spinner1(category). when nothing selected in spinner1 , spinner2 loaded item2's values. if select item1 in spinner1, loads properly. if select item2 in spinner1 nothing populated in spinner2. because of hint addition there issue think.
minimal spinner2 part in mainactivity
spinner1.setonitemselectedlistener(new adapterview.onitemselectedlistener() { @override public void onitemselected(adapterview<?> parent, view view, int position, long id) { parent.getitematposition(position).tostring(); getspinner2(id); } private void getspinner2(long id) { myrestclient.getforspinner2(mainactivity.this, "myrestservice/product/"+id, headers.toarray(new header[headers.size()]), null, new jsonhttpresponsehandler() { @override public void onsuccess(int statuscode, header[] headers, jsonarray response) { arraylist<string> spinnerarray2 = new arraylist<string>(); final spinneradapter2 spinneradapter2 = new spinneradapter2(mainactivity.this, spinnerarray2); (int = 0; < response.length(); i++) { try { jsonobject c = response.getjsonobject(i); string productarray = c.getstring("product"); spinneradapter2.add(productarray); } catch (jsonexception e) { e.printstacktrace(); } } spinneradapter2.add("select one"); spinner2.setadapter(spinneradapter2); spinner2.setselection(spinneradapter2.getcount()); spinneradapter2.setdropdownviewresource(android.r.layout.simple_spinner_dropdown_item); }
and have got show hint on spinneradapter2 class
@override public int getcount() { int count = super.getcount(); return count > 0 ? count - 1 : count; } . . public view getview(int position, view convertview, viewgroup parent) { . . if (position == getcount()) { viewholder.product.settext(""); viewholder.product.sethint(products); } else { viewholder.product.settext(products); } }
please try spinneradapter2.notifydatasetchanged();
after adding elements adapter. maybe help. , thik should add items spinnerarray2 , create adapter using object.
Comments
Post a Comment