Thursday, 15 April 2010

Android: Custom spinner does not show selected item -



Android: Custom spinner does not show selected item -

problem item selected in spinner rendered in white color, although i've set color explicitly. have no thought do. i've googled similar topics solved setting color. me didn't help. here code:

private view getformview(int position, view convertview, viewgroup parent) { view v = convertview; if (v == null) { layoutinflater inflater = ma.getlayoutinflater(); v = inflater.inflate(r.layout.f_new_program_form, null); spinner sp = (spinner) v.findviewbyid(r.id.spinnerexercises); exercisespinneradapter spadapter = new exercisespinneradapter(ma); loadtask task = new loadtask((bbbaseadapter) spadapter, urls.host + urls.allexercisesurl, ma); task.execute(); sp.setadapter(spadapter); } homecoming v; }

exercisespinneradapter.java:

public class exercisespinneradapter extends bbbaseadapter implements spinneradapter { protected jsonarray info = new jsonarray(); public exercisespinneradapter(activity a) { super(a); } @override public int getcount() { // todo auto-generated method stub homecoming this.data.length(); } @override public jsonobject getitem(int position) { seek { homecoming this.data.getjsonobject(position); } grab (jsonexception e) { e.printstacktrace(); } homecoming null; } @override public long getitemid(int position) { homecoming position; } @override public int getitemviewtype(int position) { homecoming 0; } @override public view getview(int position, view convertview, viewgroup parent) { view v = convertview; if (v == null) { v = ma.getlayoutinflater().inflate(r.layout.custom_spinner, parent, false); } textview t = (textview) v.findviewbyid(r.id.spinnertextzz); seek { t.settext(getitem(position).getstring("name")); } grab (jsonexception e) { // todo auto-generated grab block e.printstacktrace(); } t.settextcolor(color.red); homecoming v; } @override public int getviewtypecount() { // todo auto-generated method stub homecoming 1; } @override public boolean hasstableids() { // todo auto-generated method stub homecoming false; } @override public boolean isempty() { // todo auto-generated method stub homecoming false; } @override public void registerdatasetobserver(datasetobserver observer) { // todo auto-generated method stub } @override public void unregisterdatasetobserver(datasetobserver observer) { // todo auto-generated method stub } @override public view getdropdownview(int position, view convertview, viewgroup parent) { view v = convertview; if (v == null) { v = ma.getlayoutinflater().inflate(r.layout.custom_spinner, parent, false); } textview t = (textview) v.findviewbyid(r.id.spinnertextzz); seek { t.settext(getitem(position).getstring("name")); } grab (jsonexception e) { // todo auto-generated grab block e.printstacktrace(); } t.settextcolor(color.red); homecoming v; } @override public void updateentries(object data) { this.data = (jsonarray) data; notifychanges(); } public void notifychanges() { notifydatasetchanged(); } }

custom_spinner:

< textview xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/spinnertextzz" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="0dp" android:layout_margin="0dp" android:text="!" android:textappearance="?android:attr/textappearancemedium" android:textcolor = "#000000" />

what have missed?

if have methods had:

@override public int getviewtypecount() { // todo auto-generated method stub homecoming 1; } @override public boolean hasstableids() { // todo auto-generated method stub homecoming false; } @override public boolean isempty() { // todo auto-generated method stub homecoming false; } @override public void registerdatasetobserver(datasetobserver observer) { // todo auto-generated method stub }

remove them or implement. if extend baseadapter implemented. don't know illustration i've got them.

android spinner

No comments:

Post a Comment