Issue
My scenario is as follow: I'm implementing a tabhost that displays two tabs through LocalActivityManager. 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 MapView implementing 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 BroadcastReceiver 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.
Thanks in advance!
Solution
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)
}
}
Answered By - Georgy Gobozov
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.