Here is my custom toast. I also toss in an image Not sure if I ever really use the context outside of my main class. Its a hack job but then so is most of my code.
public void showToast(String sayWhat, int imageid,int length,Context context){ LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.toast_layout, (ViewGroup) findViewById(R.id.toast_layout_root)); ImageView image = (ImageView) layout.findViewById(R.id.image); image.setImageResource(imageid); TextView text = (TextView) layout.findViewById(R.id.text); text.setText(sayWhat); Toast toast = new Toast(context); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); if (length == 0){ toast.setDuration(Toast.LENGTH_LONG); }else { toast.setDuration(Toast.LENGTH_SHORT); } toast.setView(layout); toast.show(); } On Wed, May 19, 2010 at 2:15 PM, TreKing <treking...@gmail.com> wrote: > On Mon, May 17, 2010 at 10:15 AM, Gene R. <gurur...@gmail.com> wrote: > >> The problem seems to be that the Service class does not inherit the >> findViewById() method. >> > > Services don't have an accompanying UI, so this makes sense. > > >> How can one generate and display a custom Toast from a Service?? >> > > In your code you inflate a view - so why not call findViewById on that root > view? > > Also, don't use getApplicationContext() ... like, ever. > > > ------------------------------------------------------------------------------------------------- > TreKing - Chicago transit tracking app for Android-powered devices > http://sites.google.com/site/rezmobileapps/treking > > -- > 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<android-developers%2bunsubscr...@googlegroups.com> > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- Follow us on Twitter @fuliginsoftware Join the forums. http://www.fuligin.com/forums -- 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