1
I’m trying to pass the value of the Marketer to the setOnInfoWindowClickListener, but I’m not sure what is the best way to do this, can anyone help me? It even passes a value, but not the loop, IE, is not passing the value of Marker by id. my code.
Complete code
private class MapaGet extends AsyncTask<String, Void, Void> implements GoogleMap.OnInfoWindowClickListener {
// Lista onde vamos guardar os valores
List<MapasController> ListaDeController = new ArrayList<MapasController>(0);
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(ViewMaps.this);
pDialog.setMessage("Por favor, aguarde...");
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected Void doInBackground(String... arg0) {
// Creating service handler class instance
cx = new Conexao();
String jsonStr = cx.get(url);
Log.d("Resposta: ", "> " + jsonStr);
if (jsonStr != null) {
try {
// De-serialize the JSON
JSONArray jsonArray = new JSONArray(jsonStr);
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObj = jsonArray.getJSONObject(i);
MapasController mc = new MapasController();
mc.setLatitude(jsonObj.getDouble(TAG_LATITUDE));
mc.setLongitude(jsonObj.getDouble(TAG_LONGITUDE));
mc.setTitulo(jsonObj.getString(TAG_TITULO));
mc.setDescricao(jsonObj.getString(TAG_DESCRICAO));
mc.setId(jsonObj.getString(TAG_ID));
mc.setStatus(jsonObj.getString(TAG_STATUS));
mc.setData(jsonObj.getString(TAG_DATA));
mc.setUsuario(jsonObj.getString(TAG_USUARIO));
mc.setCategoria(jsonObj.getString(TAG_CATEGORIA));
// Adicionamos na lista
ListaDeController.add(mc);
Log.d ("", "get " + mc.getCategoria() + "Longitude " + mc.getLatitude() + " " + jsonObj.getString(TAG_TITULO) );
}
} catch (JSONException e) {
Log.e("tag", "Error processing JSON", e);
}
} else {
Log.e("Get: ", "Não foi possível obter quaisquer dados do url");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
// Se o tamanho da lista fo maior que zero!
if(ListaDeController.size() > 0){
for(final MapasController mc : ListaDeController){
LatLng local = new LatLng(mc.getLatitude(), mc.getLongitude());
// Seleciona o ícone de acordo com a categoria do mesmo
Marker mapa = mMap.addMarker(new MarkerOptions()
.position(local)
.title(mc.getTitulo())
.snippet(mc.getDescricao())
.draggable(true)
.icon(BitmapDescriptorFactory.fromResource(icone))
);
mMap.getCameraPosition();
mMap.moveCamera(CameraUpdateFactory.newLatLng(local));
mMap.getUiSettings().setZoomControlsEnabled(true);
mMap.animateCamera(CameraUpdateFactory.zoomTo(19), 2000, null); // animação zoom 10 com 2 segundos
}
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent in = new Intent(ViewMaps.this, DescricaoMaps.class);
in.putExtra(TAG_ID, mc.getId());
in.putExtra(TAG_TITULO, mc.getTitulo());
in.putExtra(TAG_DESCRICAO, mc.getDescricao());
in.putExtra(TAG_DATA, mc.getData());
in.putExtra(TAG_STATUS, mc.getStatus());
in.putExtra(TAG_USUARIO, mc.getUsuario());
in.putExtra(TAG_CATEGORIA, mc.getCategoria());
ViewMaps.this.startActivity(in);
}
});
}
// Dismiss the progress dialog
if (pDialog.isShowing())
pDialog.dismiss();
}
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// se o mapa não está nulo , vamos carregar
if (mMap != null) {
new MapaGet().execute();
}
}
Thanks for the answer, I’m using this loop from the Marker inside the onPostExecute, I create this class Myoninfowindowclicklistener out of the loop already with the maker and then call with a new Class() ?
– Rubens Junior
You can create within the same class, or another class. You can pass Mapascontroller mc, as parameter too.
– Marco Giovanni
Hello, I’m having a hard time putting the information you gave me in my code, can you help me a little more?
– Rubens Junior
Oops, sorry to keep you waiting. where are you trying to put the code??
– Marco Giovanni
Hello, no problem, I put the full code in the question, I’m having difficulty creating this class that suggested, in my code, I actually wanted to apply the code keeping the architecture that already has in the code
– Rubens Junior
I edited the answer, instead of implementing the Listener in the method call itself, just create a class implementing the Listener, and in the method call, you create a class instance, passing as many parameters as necessary.
– Marco Giovanni
Gee, I made the changes and keeps showing only 1 item.. rs I don’t know where I’m going wrong.. rs
– Rubens Junior
What do you mean just 1 item? I don’t understand you
– Marco Giovanni
So, I need each marketer to pass their own id to the next Activity, but it only passes 1 id, and it’s the first.. I can click on how many markers it is, which only goes in the same always. Even with these changes you told me, it keeps going the same
– Rubens Junior
Let’s go continue this discussion in chat.
– Marco Giovanni