This should be so much simpler!
I have an array of JSON objects that I populate a spinner with, the whole projects works fine if I populate the spinner with the name and value pairs but it looks bad. If I populate the spinner with just the name I lose the value. From what I can tell from reading, the only way to do this is to populate the spinner with the name, retrieve the position of the selection then go back to the array to find the value of the name in the same position as it was in the spinner, is that how it has to work??
If so how do I do that?
Here is the code to popultate the spinner,
myUsers = jsonResponse.getJSONArray("GetBusinessNamesResult");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(PropertyManagement.this, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
for (int i = 0; i < myUsers.length(); ++i)
{
try {
adapter.add(myUsers.getJSONObject(i).getString("BusinessName"));
} catch (JSONException e) {
e.printStackTrace();
}
}
Then down in my onItemSelected method, I think I have the original array in parent but I’m not sure! It is sent in as a parameter via AdapterView < ? > parent, which is code I got from a tutorial and I’m not sure what happens here.
String jsonStr = parent.getItemAtPosition(pos).toString();
So just looking at the code above, I think I have the original array and the position, or I may just have the selected name, in which case this isn’t going to work and should maybe be looking back up at myUsers???
The name value pairs are BusinessName and BusinessPhone. Do you think I can get what I need from that?
Cheers,
Mike.
Subclass BaseAdapter and use it in place of your ArrayAdapter.
Here is an example: