android - Spinner ignores conditional statements -


so got spinner entries stringarray.

string[] spinnerentries = {                 getresources().getstring(r.string.oldpoint),                 getresources().getstring(r.string.newpoint),                 getresources().getstring(r.string.gpslocation) };  spinner spinner = (spinner) findviewbyid(r.id.spinner1); arrayadapter<string> adapter = new arrayadapter<string>(this,         android.r.layout.simple_spinner_item, spinnerentries); 

i want set searchpoint depending on spinner selection, totally igonores cases except first 1 (oldpoint). doing wrong? wheter got tired or stupid, don't see problem.

public void onitemselected(adapterview<?> parent, view view, int pos, long id) {     string spinneritem = (string) parent.getitematposition(pos);     if (spinneritem.equals(getstring(r.string.oldpoint))) {         searchpoint = r.string.oldpoint;     } else if (spinneritem.equals(r.string.newpoint)) {         searchpoint = r.string.newpoint;     } else if (spinneritem.equals(r.string.gpslocation)) {         searchpoint = r.string.gpslocation;     } } 

in first conditional, you're correctly calling getstring() on constant name. however, on second 2 else blocks, you're not.

// correct if (spinneritem.equals(getstring(r.string.oldpoint))) {     searchpoint = r.string.oldpoint;  // need call getstring() on r.string.newpoint } else if (spinneritem.equals(r.string.newpoint)) {     searchpoint = r.string.newpoint;  // need call getstring() on r.string.gpslocation } else if (spinneritem.equals(r.string.gpslocation)) {     searchpoint = r.string.gpslocation; } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -