Gaston de la cruz Gaston de la cruz - 4 years ago 111
Android Question

how to access to a variable form an inner class without declaring it as final

I have a variable that I need to use in an inner class but the only way java letme uset it it´s declaring it as final, but I need to use it without it, letme paste you the code:

for (Taxi taxi : taxis) {
final Ubicaciones u= taxi.getUbicacionActual();
LatLng ubicacion= new LatLng(Double.parseDouble(u.getLatitud()), Double.parseDouble(u.getLongitud()));


MarkerOptions punto= new MarkerOptions().position(ubicacion);

map.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
public View getInfoWindow(Marker marker) {
return null;

public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.info_title,null);

TextView info1= (TextView) v.findViewById(;
TextView info2= (TextView) v.findViewById(;
TextView info3= (TextView) v.findViewById(;
info1.setText("Fecha: "+u.getFecha());
info3.setText("Longitud: "+u.getLongitud().toString());

return v;

The variable it´s "Ubicaciones u", as you can see in the code it´´t declared as final, could someone tell me how can I use it without that, best regards.

Answer Source

Declare the required variable as global it will solve your problem. But I would recommend you to go through answers here.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download