Re: [android-developers] Re: Fragments for Google Maps add on?
Thanks for all your input I did get it working. Dan On May 2, 2011 4:16 PM, Streets Of Boston flyingdutc...@gmail.com wrote: You cannot replace a *fragment *(e.g. your ImageView fragment) directly with an *activity *(in your case a subclass of AFragmentMapActivity). Don't confuse Activities with Fragments. Have your main Activity, that hosts the Map fragment (and possibly other fragments as well), extend AFragmentMapActivity. In my example that is 'Main'. Then inflate in your main Activity a layout with a fragment that contains a MapView. In my example that is 'MapFragment'. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Fragments for Google Maps add on?
I'm still having issues. I'm using the honeycombgallery sample from the android site and am tring to remove the ImageView fragment (that shows the image in the bottom right) and replace it with a AFragmentMapActivity. The samples Main uses multiple fragments and I would like to continue doing that but with the replacement of one of them to a AFragmentMapActivity. The sample works if i have the mainactivity extend from AFragmentActivity and leave all original fragments in place but when I try to extend from AFragmentMapActivity and replace the ImageView fragment with a MapActivity AFragmentMapActivity I can't get things to work. Would you have any pointers as to how I could change the code to make this example work? On Apr 30, 6:04 pm, Streets Of Boston flyingdutc...@gmail.com wrote: The new contents of FragmentActivity.java are in my earlier post. The AFragmentActivity.java is a copy of the original FragmentActivity.java with these additional changes: - public class AFragmentActivity extends Activity *implements FragmentActivity* - Then fix the compiler errors from the change above (i.e. implement missing methods that are defined by the FragmentActivity). This is pretty trivial. The AFragmentMapActivity is a copy of the AFragmentActivity with these additional changes: - public abstract class AFragmentMapActivity extends *Map*Activity implements FragmentActivity Then you'll find that other source files in the compatibility have some compiler errors. These are trivial to fix. Mostly adding (Context) or (Activity) casts and calling '.getFragments()' instead of '.mFragments' and such. Here is a usage example: *public class Main extends AFragmentMapActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }* * @Override protected boolean isRouteDisplayed() { return false; } }* *public class MapFragment extends Fragment { private View fragmentView; private MapView mapView;* * @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { fragmentView = inflater.inflate(R.layout.map, container, false); mapView = (MapView)fragmentView.findViewById(R.id.mapview); return fragmentView; }* *}* And the layout main.xml has a fragment in there that refers to * MapFragment*. * * - - -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: Fragments for Google Maps add on?
Thanks for the response this all makes perfect sense. I've. Made the changes and hope to try it out today some time. Thanks again... Dan On Apr 30, 2011 6:05 PM, Streets Of Boston flyingdutc...@gmail.com wrote: The new contents of FragmentActivity.java are in my earlier post. The AFragmentActivity.java is a copy of the original FragmentActivity.java with these additional changes: - public class AFragmentActivity extends Activity *implements FragmentActivity* - Then fix the compiler errors from the change above (i.e. implement missing methods that are defined by the FragmentActivity). This is pretty trivial. The AFragmentMapActivity is a copy of the AFragmentActivity with these additional changes: - public abstract class AFragmentMapActivity extends *Map*Activity implements FragmentActivity Then you'll find that other source files in the compatibility have some compiler errors. These are trivial to fix. Mostly adding (Context) or (Activity) casts and calling '.getFragments()' instead of '.mFragments' and such. Here is a usage example: *public class Main extends AFragmentMapActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }* * @Override protected boolean isRouteDisplayed() { return false; } }* *public class MapFragment extends Fragment { private View fragmentView; private MapView mapView;* * @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { fragmentView = inflater.inflate(R.layout.map, container, false); mapView = (MapView)fragmentView.findViewById(R.id.mapview); return fragmentView; }* *}* And the layout main.xml has a fragment in there that refers to * MapFragment*. * * - - -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Fragments for Google Maps add on?
You cannot replace a *fragment *(e.g. your ImageView fragment) directly with an *activity *(in your case a subclass of AFragmentMapActivity). Don't confuse Activities with Fragments. Have your main Activity, that hosts the Map fragment (and possibly other fragments as well), extend AFragmentMapActivity. In my example that is 'Main'. Then inflate in your main Activity a layout with a fragment that contains a MapView. In my example that is 'MapFragment'. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Fragments for Google Maps add on?
The new contents of FragmentActivity.java are in my earlier post. The AFragmentActivity.java is a copy of the original FragmentActivity.java with these additional changes: - public class AFragmentActivity extends Activity *implements FragmentActivity* - Then fix the compiler errors from the change above (i.e. implement missing methods that are defined by the FragmentActivity). This is pretty trivial. The AFragmentMapActivity is a copy of the AFragmentActivity with these additional changes: - public abstract class AFragmentMapActivity extends *Map*Activity implements FragmentActivity Then you'll find that other source files in the compatibility have some compiler errors. These are trivial to fix. Mostly adding (Context) or (Activity) casts and calling '.getFragments()' instead of '.mFragments' and such. Here is a usage example: *public class Main extends AFragmentMapActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); }* * @Override protected boolean isRouteDisplayed() { return false; } }* *public class MapFragment extends Fragment { private ViewfragmentView; private MapView mapView;* * @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { fragmentView = inflater.inflate(R.layout.map, container, false); mapView = (MapView)fragmentView.findViewById(R.id.mapview); return fragmentView; }* *}* And the layout main.xml has a fragment in there that refers to * MapFragment*. * * - - -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: Fragments for Google Maps add on?
Hay, I’m curious if you could share the source code of the two file you are talking about here and maybe a usage example... Thanks, Dan On Apr 25, 6:18 pm, Streets Of Boston flyingdutc...@gmail.com wrote: The option from Valentin in stackoverflow doesn't work well with the *compatibility library*. This is what i did to make it MapActivity work with Fragments using the compatibility library (it is not the best solution, but it seems to work so far): 1. Use the source of the compatibililty library (just copy android/* into your project's source dir). 2. Rename (don't refactor!) FragmentActivity.java into AFragmentActivity.java (rename file and class-name). 3. Create a new java file FragmentActivity.java. Make it an interface (see below). 4. Have AFragmentActivity implement FragmentActivity. *public class AFragmentActivity extends Activity implements FragmentActivity ... * 1. Fix the compiler errors that will happen. 2. instead of .mFragments, use getFragments() 3. instead of mHandler, use getHandler() 4. add casts that will cast FragmentActivity into Context or Activity where necessary. 5. etc. 5. After all compiler errors have been fixed, make a copy of AFragmentActivity.java and call it AFragmentMapActivity.java and have it extend MapActivity *public abstract class AFragmentMapActivity extends MapActivity implements FragmentActivity ...* Now you can have a MapView in a regular fragment as long as that fragment is hosted inside a AFragmentMapActivity. Source of the FragmentActivity interface (without the imports and such): *package android.support.v4.app;* *...* *...* *public interface FragmentActivity { public ClassLoader getClassLoader(); public View findViewById(int mViewId); public Context getApplicationContext(); public Resources getResources(); public Window getWindow(); public LayoutInflater getLayoutInflater(); public boolean isFinishing(); public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo);* ** * public FragmentManagerImpl getFragments(); public Handler getHandler();* ** * public LoaderManagerImpl getLoaderManager(int mIndex, boolean mLoadersStarted, boolean b); public CharSequence getText(int mBreadCrumbTitleRes); public void invalidateFragmentIndex(int mIndex); public void onAttachFragment(Fragment f); public void startActivityFromFragment(Fragment fragment, Intent intent, int i); public void supportInvalidateOptionsMenu(); }*- Hide quoted text - - Show quoted text - -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en