請幫我設置TextView的文本在自定義通知如何設置自定義通知的TextView價值
private void startNotification()
{
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager notificationManager = (NotificationManager) getSystemService(ns);
Notification notification = new Notification(R.drawable.ic_launcher, null, System.currentTimeMillis());
RemoteViews notificationView = new RemoteViews(getPackageName(),R.layout.mynotification);
mRemoteViews.setTextViewText(R.id.appName, getResources().getText(0,"gfhf"));
mBuilder.setContent(mRemoteViews);
Intent notificationIntent = new Intent(this, FlashLight.class);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.contentView = notificationView;
notification.contentIntent = pendingNotificationIntent;
notification.flags |= Notification.FLAG_NO_CLEAR;
Intent switchIntent = new Intent(this, switchButtonListener.class);
PendingIntent pendingSwitchIntent = PendingIntent.getBroadcast(this, 0, switchIntent, 0);
notificationView.setOnClickPendingIntent(R.id.closeOnFlash, pendingSwitchIntent);
notificationManager.notify(1, notification);
}
顯示java.lang.NullPointerException:試圖調用虛擬方法無效 android.widget .RemoteViews.setTextViewText(INT, java.lang.CharSequence中的)」對空對象引用
請幫助我如何解決這個問題。如何設置android中的通知textview上的值,在此先感謝。
你到底要什麼?你想用自定義樣式textView創建自定義通知嗎?爲此創建自定義類並覆蓋DefaultNotificationFactory並創建您自己的視圖 –