T
theAydinator
Neues Mitglied
- 0
Guten Morgen,
ich habe folgendes Problem:
Ich versuche eine App zu schreiben, dass beim Betätigen der InfoWindows eines Markers die jeweilige location_id (aus der Datenbank) an die LocationDetails Activity übersenden wird.
Habe das Problem, dass immer die letzte ID übergeben wird.
Wenn ich aus der Methode LocationDetails den Typ "final" entferne, bekomme ich die Meldung:
Cannot refer to a non-final variable location_id inside an inner class defined in a different method
Ich würde mich über hilfreiche Tipps sehr freuen.
Grüße
Aydin
ich habe folgendes Problem:
Ich versuche eine App zu schreiben, dass beim Betätigen der InfoWindows eines Markers die jeweilige location_id (aus der Datenbank) an die LocationDetails Activity übersenden wird.
Habe das Problem, dass immer die letzte ID übergeben wird.
Code:
void createMarkersFromJson(String json) throws JSONException {
JSONArray jsonArray = new JSONArray(json);
System.out.print(json);
List<Marker> markers = new ArrayList<Marker>();
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObj = jsonArray.getJSONObject(i);
String location_id = jsonObj.getString("location_id");
System.out.print(jsonObj.getJSONArray("latlng"));
Marker marker = mapB.addMarker(new MarkerOptions()
.title(jsonObj.getString("organization"))
.position(new LatLng(
jsonObj.getJSONArray("latlng").getDouble(0),
jsonObj.getJSONArray("latlng").getDouble(1)))
.snippet(jsonObj.getString("location"))
.icon(BitmapDescriptorFactory.fromResource(R.drawable.marker))
);
markers.add(marker);
LocationDetails(location_id);
}
}
public void LocationDetails(final String location_id) {
mapB.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent intent = new Intent(MainActivity.this, LocationDetail.class);
intent.putExtra("location_id", location_id);
startActivity(intent);
//push from bottom to top
overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
}
});
}
Wenn ich aus der Methode LocationDetails den Typ "final" entferne, bekomme ich die Meldung:
Cannot refer to a non-final variable location_id inside an inner class defined in a different method
Ich würde mich über hilfreiche Tipps sehr freuen.
Grüße
Aydin