如何动态添加图像到RemoteView下的ViewFlipper

时间:2016-01-12 18:49:08

标签: android android-imageview android-pendingintent viewflipper android-remoteview

我需要将一个图像列表加载到RemoteView中。为此,我使用ViewFlipper显示用户单击下一个和上一个按钮的时间。但是我遇到ViewFlipper的问题是我无法动态添加图像,而如果我从ViewFlipper内部的drawables加载图像,我会得到一次输出。请帮忙。我无法使用RemoteViews找到解决方案。我发布的代码供您参考,如下所示:

 @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);
    }

任何提示和提示对我都有帮助。提前谢谢。

1 个答案:

答案 0 :(得分:0)

只是偶然发现了这个问题,看到没有人回答......这是我在远程视图中将childs添加到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