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()));


map.moveCamera(CameraUpdateFactory.newLatLngZoom(ubicacion,15));

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

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

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


TextView info1= (TextView) v.findViewById(R.id.info1);
TextView info2= (TextView) v.findViewById(R.id.info2);
TextView info3= (TextView) v.findViewById(R.id.info3);
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