I want to create custom Toast view like
public class SMSToast extends Activity {
public void showToast(Context context, String message) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.toast_sms, (ViewGroup)findViewById(R.id.toast_sms_root));
TextView text = (TextView) layout.findViewById(R.id.toast_sms_text);
text.setText(message);
Toast toast = new Toast(context);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
}
and in BroadcastReceiver on onReceive method
SMSToast toast = new SMSToast();
toast.showToast(context,
"Received SMS from: " + msg_from +
" Content: " + msgBody);
but no message is shown when the code is called. If i use Toast then text is shown. What i am doing wrong?
Do not extend the SMSToast class from an Activity. make it a simple java class.