Re: [android-developers] Re: Toast - I can't get it to work in Eclipse...
furby wrote: To be sure that you have some idea of what I am talking about, here is the code for the entire class : import java.util.ArrayList; import android.graphics.drawable.Drawable; import android.widget.Toast; import com.google.android.maps.ItemizedOverlay; import com.google.android.maps.OverlayItem; public class HelloItemizedOverlay extends ItemizedOverlay { private ArrayListOverlayItem mOverlays = new ArrayListOverlayItem (); public HelloItemizedOverlay(Drawable defaultMarker) { super(boundCenterBottom(defaultMarker)); } @Override protected OverlayItem createItem(int i) { return mOverlays.get(i); } @Override public int size() { return mOverlays.size(); } public void addOverlay(OverlayItem overlay) { mOverlays.add(overlay); populate(); } protected boolean onTap(int index) { Toast.makeText(HelloItemizedOverlay.this, TEST, Toast.LENGTH_SHORT).show(); return super.onTap(index); } } The first parameter to makeText() needs to be a Context, such as an Activity. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy _Android Programming Tutorials_ Version 1.0 Available! -- 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: Toast - I can't get it to work in Eclipse...
furby wrote: Hmmm Am I putting the onTap handler in the wrong place? I thought that it would go in the overlay handler Your onTap() is in the correct place. However, HelloItemizedOverlay is not a Context, and so it cannot be used as the first parameter to makeText(). Either make HelloItemizedOverlay an inner class of your MapActivity, or pass the MapActivity as a parameter to the HelloItemizedOverlay constructor, or something, then use that object as the first parameter to makeText(). -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Consulting/App Development: http://commonsware.com/consulting -- 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: Toast - I can't get it to work in Eclipse...
furby wrote: Perhaps I am going about this the wrong way... it seems like a lot of shifting of code around to get a simple message to display in google maps. Not really. Let me rephrase the question : Is there a simple way to get the two String parameters to display (That are sent to the OverlayItem class) when a point is clicked on? I would assume that google maps woudl have somethign built in (I am used to using maps in Javascript where it's pretty much just a onClick event handler...). You are using the simple way. You just have the wrong type for the first parameter to the makeText() method. It would similarly fail if you tried passing an integer for the first parameter, or a boolean. You can see an example of using a Toast from an ItemizedOverlay in one of my book examples. I don't have these examples up on github just yet (probably this weekend), so I can't directly link to it. For now, visit: http://commonsware.com/Android/ Scroll down and click on the Source Code link opposite the table of contents. In the ZIP file, you will see Maps/NooYawk/. Look for the onTap() implementation there. Since my ItemizedOverlay is an inner class of my MapActivity, I already have access to a suitable Context to provide to makeText(). -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Android Development Wiki: http://wiki.andmob.org -- 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