I have a tabActivity which is composed of 2 view and a map activity. At this level, no problems.
When I clicked on the tab, the mapActivity appears correctly
My problem is how pass some data (like a String) from the TabActivity to the mapActivity. When it's to pass data to view, no problems because the view are instantiate directly. However the tab with map activity is instantiate only when I clicked on the tab.
See my code :
Using java Syntax Highlighting
- public class TabbedActivity extends MapActivity implements TabContentFactory {
- InfoContactActivity infoView;
- InfoSupplActivity infoSupplView;
- MapviewActivity mapView;
- TabHost tabHost;
- Bundle objetbunble;
- String idtosearch;
- GetInfoAsyncTask asyncTask;
- [...]
- public TabbedActivity() {
- this(true);
- }
- public TabbedActivity(boolean singleActivityMode) {
- [...]
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- Bundle states = savedInstanceState != null ? (Bundle) savedInstanceState.getBundle(STATES_KEY): null;
- mLocalActivityManager.dispatchCreate(states);
- setContentView(R.layout.tab_layout);
- Resources res = getResources();
- tabHost = (TabHost) findViewById(R.id.tabhost);// The activity TabHost
- tabHost.setup(mLocalActivityManager);
- TabHost.TabSpec spec; // Resusable TabSpec for each tab
- // recuperation des données supp de l'intent d'ouverture de lactivity
- objetbunble = this.getIntent().getExtras();
- // récupération de la valeur qui nous interresse
- idtosearch = objetbunble.getString("idtosearch");
- infoView = new InfoContactActivity(getApplicationContext());
- infoSupplView = new InfoSupplActivity(getApplicationContext());
- mapView = new MapviewActivity();
- // Initialize a TabSpec for each tab and add it to the TabHost
- spec = tabHost.newTabSpec("info").setIndicator("",
- res.getDrawable(R.drawable.id_card)).setContent(this);
- tabHost.addTab(spec);
- // Do the same for the other tabs
- spec = tabHost.newTabSpec("infosupp").setIndicator("",
- res.getDrawable(R.drawable.email)).setContent(this);
- tabHost.addTab(spec);
- // Map
- Context ctx = this.getApplicationContext();
- Intent i = new Intent(ctx, TabbedActivity.class);
- spec = tabHost.newTabSpec("map").setIndicator("",res.getDrawable(R.drawable.globe)).setContent(new Intent(this,MapviewActivity.class));
- tabHost.addTab(spec);
- tabHost.setCurrentTab(0);
- asyncTask = new GetInfoAsyncTask();
- asyncTask.execute();
- }
- @Override
- protected void onResume() {
- super.onResume();
- mLocalActivityManager.dispatchResume();
- }
- [...]
- @Override
- protected void onProgressUpdate(Object... values) {
- // TODO Auto-generated method stub
- if (values[0] instanceof PersonDetailDataSet) {
- PersonDetailDataSet parsedDataSet = (PersonDetailDataSet) values[0];
- if (infoView != null) {
- infoView.setInfo(parsedDataSet);
- }
- if (infoSupplView != null) {
- infoSupplView.setInfo(parsedDataSet);
- }
- [...]
- public View createTabContent(String tag) {
- View view = null;
- if (tag.compareTo("info") == 0) {
- view = infoView;
- } else if (tag.compareTo("infosupp") == 0) {
- view = infoSupplView;
- }
- return view;
- }
- }
Parsed in 0.040 seconds, using GeSHi 1.0.8.4
Using java Syntax Highlighting
- public class MapviewActivity extends MapActivity {
- MapView infoMapView;
- Hashtable<String, GeoPoint> siteToGeopoint = new Hashtable<String, GeoPoint>();
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- setContentView(R.layout.maplayout);
- infoMapView = (MapView) findViewById(R.id.map);
- infoMapView.setBuiltInZoomControls(true);
- infoMapView.setClickable(true);
- infoMapView.getController().setZoom(14);
- public void setInfo(PersonDetailDataSet parsedDataSet) {
- if (infoMapView != null) {
- String site = parsedDataSet.getSiteName();
- if (site != null) {
- GeoPoint gp = siteToGeopoint.get(site);
- if (gp != null) {
- infoMapView.getController().setCenter(gp);
- List<Overlay> mapOverlays = infoMapView.getOverlays();
- mapOverlays.clear();
- ContactItemizedOverlay overlay = new ContactItemizedOverlay(
- getResources().getDrawable(R.drawable.toto));
- OverlayItem overlayitem = new OverlayItem(gp, "Me", "");
- overlay.addOverlay(overlayitem);
- mapOverlays.add(overlay);
- }
- }
- }
- }
- protected boolean isRouteDisplayed() {
- // TODO Auto-generated method stub
- return false;
- }
- }
Parsed in 0.035 seconds, using GeSHi 1.0.8.4

