[android-developers] Custom Toast
Hello,
I am trying to display a "custom" Toast from a service. I have no
problem displaying a regular Toast from my service using
Toast.makeText() and Toast.show(); however, I would like to display a
custom Toast with an embedded graphic. The problem seems to be that
the Service class does not inherit the findViewById() method. How can
one generate and display a custom Toast from a Service??
public class DialHelper extends Service {
public void onCreate() {
super.onCreate();
// Get the notification manager service.
}
@Override
public void onStart(Intent i,int startid) {
LayoutInflater inflater = LayoutInflater inflater =
(LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.toast_layout,
(ViewGroup)
findViewById(R.id.toast_layout_root)); // Service does not inherit
the findViewById() methods!!!!!
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);
TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello! This is a custom toast!");
Toast toast = new Toast(getApplicationContext());
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
...
}
--
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+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home