我想上的onReceive方法Creatinng定製吐司視圖
SMSToast toast = new SMSToast();
toast.showToast(context,
"Received SMS from: " + msg_from +
" Content: " + msgBody);
創建像
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();
}
}
和在廣播接收器的定製吐司視圖但是當代碼被稱爲沒有顯示消息。如果我使用Toast,則會顯示文字。我做錯了什麼?
SMSToast吐司=新SMSToast(); toast.showToast(context,msg);這可能以這種方式調用活動的方法嗎? – 2012-08-13 11:42:11