Cómo sincronizar listview y mapview con TabHost en Android

My scenario is as follow: I'm implementing a tabhost that displays two tabs through Administrador de actividad local. The first one holds a ListView that shows information about a geo-localized position (such distance, address name...), and in the second one, I have a Vista del mapa implementación Google's Map API that shows the respective items within the first activity. I can't implement both activities as one, in same view, because the two extends from different classes (the first one has a parent that creates a custom menu and the second one comes from MapView), so the option to do all things in one activity is not available.

My issue is: having a lazy-load (load content in demand, when user scrolls to the end of the list) feature in the first activity, how can I synchronize its items in the MapView activity, using the TabHost methods?

I've stated with some complex solutions already, such using Receptor de radiodifusión or creating AIDL, but I'm looking for the simplest possible solution. I'm not seeking for code itself but a plan to do this task.

Gracias de antemano!

preguntado el 31 de julio de 12 a las 15:07

1 Respuestas

I thik in this case you need to implement listener pattern, for example

 public interface MapDataLoadingListener{
    public void onMapDataLoaded(List<MapData> dataList);
}

public class YourListActivity extends Activity{

    ...

    // somewhere you push yoy lazy load task
    UpdateListTask task = new UpdateListTask();
    task.setMapDataListener(// your map activity)
    task.execute();
    ...
}


public class YourMapActivity extends MapActivity implements MapDataLoadingListener {

     ...

     public void onMapDataLoaded(List<MapData> dataList){
        updateMap(dataList); 
     }

    ...

    private void updateMap(List<MapData> dataList){
        ...
    }

}


public class UpdateListTask extends AsyncTask {

    private MapDataLoadingListener mapDataListener;

    public void setMapDataListener(MapDataLoadingListener mapDataListener){
        this.mapDataListener = mapDataListener;
    }

    ...

    @Override
    protected void onPostExecute(Object result) {
       mapDataListener.onMapDataLoaded((List<MapData>) result)
    }

}

Respondido 01 ago 12, 22:08

Hi Georgy, I've already solved this by using the parent Activity (the activity that extends from ActivityGroup) and a combination of the methods Activity:getParent() and Activity:getActivity(StringId) to pass data with a flow-type of [child1->parent->child2]. I gonna accept your answer as it is also a very good one. Thanks for the reply! - Marcelo

You are welcome. But keep it mind that ActivityGroup now is deprecated class. - Gueorgui Gobozov

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.