I am able to display a custom Toast from an Activity; however, a
service does not inherit the findViewById() method needed to build the
custom Toast.  Is there a way around this?  See below:

public class CService extends Service {
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public void onStart(Intent i,int startid) {
        LayoutInflater inflater = getLayoutInflater();
        View layout = inflater.inflate(R.layout.toast_layout,
                               (ViewGroup)
findViewById(R.id.toast_layout_root));  // I get error: method
findViewById is undefined for CService

        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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to