2013-01-20 55 views
2

我有2個remoteViewsAndroid的通知內容不會顯示出來

  1. 的通知內容
  2. 的通知股票代碼(這不會工作,我認爲)

我還沒有爲代碼2.一旦我得到內容的工作,我會嘗試2.

代碼低於

Intent intent = new Intent(this, HomeScreen.class); 
    PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); 

    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.pickupnotification); 
    RelativeLayout pickupNotificationLayout = (RelativeLayout)this.getLayoutInflater().inflate(R.layout.pickupnotification, null) ; 
    TextView title = (TextView)pickupNotificationLayout.findViewById(R.id.title) ; 
    TextView countDown = (TextView)pickupNotificationLayout.findViewById(R.id.countDown) ; 
    TextView from = (TextView) pickupNotificationLayout.findViewById(R.id.from) ; 
    TextView to = (TextView) pickupNotificationLayout.findViewById(R.id.to) ; 
    contentView.apply(this, pickupNotificationLayout); 

    title.setText("Siddharth" + "2km -> 20km"); 
    countDown.setText("-1:29") ; 
    from.setText("FROM 2:00pm 14th Jan 2013, Some address") ; 
    to.setText("TO 4:00pm 14th Jan 2013 Some address") ;   
    Notification noti = new NotificationCompat.Builder(this).setContent(contentView) 
      .setSmallIcon(R.drawable.notification_logo) 
      .setContentIntent(pIntent) 
      .build(); 
    NotificationManager notificationManager = 
     (NotificationManager) getSystemService(NOTIFICATION_SERVICE); 
    noti.flags |= Notification.FLAG_AUTO_CANCEL; 
    notificationManager.notify(0, noti); 

notification swipe down image

回答

1

你不應該誇大所有的觀點一樣,多次,我相信,你認爲該文本被放置並在框架認爲被放置文本是不一樣的。填入內容的代碼應該看起來更像這樣,使用RemoteViews上提供的方法。

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.pickupnotification); 

contentView.setTextViewText(R.id.title, "Siddharth" + "2km -> 20km"); 
contentView.setTextViewText(R.id.countDown, "-1:29"); 
contentView.setTextViewText(R.id.from, 
     "FROM 2:00pm 14th Jan 2013, Some Address"); 
contentView.setTextViewText(R.id.to, 
     "TO4:00pm 14th Jan 2013 Some address"); 

Notification noti = new NotificationCompat.Builder(this) 
     .setContent(contentView) 
     .setSmallIcon(R.drawable.notification_logo) 
     .setContentIntent(pIntent) 
     .build(); 

很明顯,你會想要做一個類似的模式與股票視圖以及。

+1

謝謝。我會嘗試一下並報告。但我解決了我當前的問題,'noti.contentView = contentView;'。我想知道爲什麼setContent不起作用。 – Siddharth

+0

我想知道爲什麼setContent不起作用? – Siddharth

+0

工作!你是對的,我不需要膨脹。但是我仍然不能讓佈局完全顯示它隱藏在標籤背後(通知/快速設置)的內容。 – Siddharth