私はホームスクリーンウィジェットを構築しています。私の目標は、このウィジェット内の ImageView に画像を設定することであり、これに使用setImageViewResource()
します。そして、それは完全に機能します-つまり、ターゲットイメージは実行後にR.id.user_button
イメージリソースを変更しますR.drawable.activity_notification
onStart()
-次のように使用すると:
public class UpdateWidgetService extends Service {
public void onStart(Intent intent, int startId) {
... //Some code which is not really important
RemoteViews remoteViews = new RemoteViews(this.getPackageName(),R.layout.widget_layout);
remoteViews.setImageViewResource(R.id.user_button, R.drawable.activity_notification);
}
}
問題は、外部関数setImageViewResource()
内に配置する必要があり、以下のコードのようなものをビルドしようとすると、動作を拒否することです。つまり、ターゲット イメージのイメージ リソースは、実行後も変更されません。R.id.user_button
onStart()
public class UpdateWidgetService extends Service {
public void onStart(Intent intent, int startId) {
... //Some code which is not really important
changeImagePicture();
}
public void changeImagePicture() {
RemoteViews remoteViews = new RemoteViews(this.getPackageName(),R.layout.widget_layout);
remoteViews.setImageViewResource(R.id.user_button, R.drawable.activity_notification);
}
}
私は初心者だと思いますが、ここで本当に単純で非常に重要なことを見逃しています。最後に私のコードを動作させることができるように、私の間違いを指摘していただけますか ;) Merci beaucoup!