2011-01-14 57 views
2

如何在我的控件中有一個圖像,然後當它被點擊更改爲另一圖像?它只有一個ImageButton的小部件,但我不知道該去哪裏,我知道所有關於懸而未決的意圖等,但這在這裏沒有幫助,除非我錯過了一些東西......這是我的onUpdate在控件中更改圖片

public void onUpdate(Context context,AppWidgetManager appWidgetManager,int[] appWidgetIds){ 
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); 
    PendingIntent onPendingIntent = PendingIntent.getService(context, 0, new Intent(context, widgetService.class), 0); 
    remoteViews.setOnClickPendingIntent(R.id.ImageButton01, onPendingIntent); 
    appWidgetManager.updateAppWidget(appWidgetIds, remoteViews); 
} 

回答

1

嘗試了這一點:

public void onUpdate(Context context,AppWidgetManager appWidgetManager,int[] appWidgetIds){ 
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget); 
    PendingIntent onPendingIntent = PendingIntent.getService(context, 0, new Intent(context, widgetService.class), 0); 

    remoteViews.setOnClickPendingIntent(R.layout.widget2, onPendingIntent); 
             **add widgetON.xml* 

擁有了 「widgetON」 像一個單獨的.xml佈局。 (Widget2) 然後,你必須弄亂remoteViews來區分開/關視圖

我想。 :d

5

我覺得這是你找什麼

/* get the handle on your widget*/ 
RemoteViews views = new RemoteViews(getPackageName(), R.layout.your_widget_layout); 
/* replace the image */ 
views.setBitmap(R.id.id_of_your_imageview, "setImageBitmap", yourBitmap); 

/* update your widget */ 
ComponentName thisWidget = new ComponentName(this, YourWidget.class); 
AppWidgetManager manager = AppWidgetManager.getInstance(this); 
manager.updateAppWidget(thisWidget, updateViews); 
+0

只是clarifiy,要做到這一點在onReceiver您的廣播接收機的 – urSus 2012-10-20 21:35:20