0

我有要求將圖像列表加載到RemoteView中。爲此,我使用ViewFlipper來顯示用戶何時單擊下一個和上一個按鈕。但是我面對ViewFlipper的問題是我無法動態地添加圖像,而如果我在ViewFlipper本地加載繪圖的圖像,則會獲得一次輸出。請幫忙。我無法通過RemoteViews找到解決方案。我張貼我的代碼,供您參考如下:如何將圖像動態添加到RemoteView下的ViewFlipper中

@Override 
public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     RemoteViews expandedView = new RemoteViews(this.getPackageName(), R.layout.notification_viewflipper); 
     expandedView.setOnClickPendingIntent(R.id.img_left,getPendingSelfIntent(MainActivity.this, IMAGE_LEFT)); 
     expandedView.setOnClickPendingIntent(R.id.img_right,getPendingSelfIntent(MainActivity.this, IMAGE_RIGHT)); 

} 

protected PendingIntent getPendingSelfIntent(Context context, String action) { 
     Intent intent = new Intent(context,MyNotificationReceiver.class); 
     intent.setAction(action); 
     return PendingIntent.getBroadcast(context, 0, intent, 0); 
    } 

任何種類的技巧和提示的將是對我很大的幫助。提前致謝。

回答

0

只是偶然uppon這個問題,看到沒有人回答...這是我的代碼,以孩子的添加到viewFlipper一個遠程視窗內:

RemoteViews carrouselItem = new RemoteViews(getPackageName(), R.layout.item_carrousel_notification); 
contentView1.setImageViewResource(R.id.product_image, R.drawable.ic_launcher); 
contentView1.setTextViewText(R.id.notification_title, "First Product"); 

RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.carrousel_notification); 
contentView.addView(R.id.notification_view_flipper, carrouselItem); 

替換R.drawable.ic_launcher與您要添加的圖像到viewflipper(從url或其他來源得到它)。猜猜應該工作。我的問題是在擴展通知中使用viewflipper =/

相關問題