I have locations save in the database and I am trying to retrieve them into a ListView
. Each location has a name, a latitude and a longitude but the only thing that I am trying to display on the list in the name of the location and leave the latitude and longitude in the background so I can save them to the database based on what the location name selected by the user in the ListView
.
Here is my current code:
public void onResponse(JSONArray response) {
for (int i = 0; i < response.length(); i++) {
JSONObject object = null;
try {
object = response.getJSONObject(i);
items.add(object.getString("locationName")); items.add(object.getString("latitude")); items.add(object.getString("longitude"));
} catch (JSONException e) {
e.printStackTrace();
}
}
ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), R.layout.location, items);
listView.setAdapter(adapter);
FuturaTextViewBold listviewHearder = (FuturaTextViewBold) customView.findViewById(R.id.tv_header);
listviewHearder.setBackgroundColor(Color.GREEN);
listviewHearder.setText("SELECT A LOCATION");
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String SelectedItem = (String) listView.getItemAtPosition(position);
startLocation.setText(SelectedItem);
}
});
}