I'm trying to figure out a way to pass multiple parameters when a user clicks a string using my app. I can currently only pass one string but I have to pass another string as well. I'm passing a city (IE an actually city string, Boston, Miami etc..). My goal is to pass the associated state along with the city. For example, Boston would also pass Massachusetts, Mimi would pass Florida etc...
My question is, how would I pass the state parameter that's associated with that city?
The information I'm passing is coming from a URL on the internet
My URL looks like this http://mywebsite.com/getDealershipCity.php?StateID=florida&CityID=miami
getAllCitiesTextView.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String cityClicked = null;
try {
cityClicked = jsonArray.getString(position);
} catch (JSONException e) {
e.printStackTrace();
}
Log.e("showing position before method = ", cityClicked);
APIConnector haveToAccessAMethod = new APIConnector();
String cityClickedAfterMethod = haveToAccessAMethod.returnTheCityString(cityClicked);
Log.e("showing position after method = ", cityClickedAfterMethod);
Intent show = new Intent(getApplicationContext(), DealerDetailsActivity.class);
show.putExtra("cityID", cityClickedAfterMethod);
startActivity(show);
}
});
}
As @cYrixmorten suggests, you could create a holder class that implements Parcelable
and put that in your intent
as an extra. You could also just put another extra in the intent that contains the state that's associated with the city. If you opted for that (shorter) solution, it would look something like this:
String stateClickedAfterMethod = ...
Intent show = new Intent(getApplicationContext(), DealerDetailsActivity.class);
show.putExtra("cityID", cityClickedAfterMethod);
show.putExtra("state", stateClickedAfterMethod);