2012-05-23 85 views
0

我寫了一個widget,它會根據我的配置每兩個小時自動更新一次內容。但是如何通過按下小部件中的按鈕來手動刷新它。感謝您的評論。android widget手動刷新

回答

0

您需要在控件上調用invalidate()。見借鑑this page.

class myActivity extends Activity{ 
    MyButton myButton = null; 
... 
onCreate(){ 
    myButton = findViewById(...); 
... 
myMethodWhereIWantToRefreshMyButton(){ 
    myButton.invalidate(); 
+0

能否詳細說明一下,因爲我不知道該怎麼做,非常感謝! – user1411475

+0

對不起,我的意思是手動刷新小部件,按下小部件中的按鈕,而不是在活動中..... – user1411475

+0

然後在該按鈕的onClick中調用myControl.invalidate()。 – cstrutton

1

你必須把一個按鈕layout_wid.xml文件。

onUpdate()

,你必須找到你的button.and放click事件的ID,刷新你的widget

Intent imageview2Intent= new Intent(context, WatchWidget.class); 
PendingIntent pendingIntent= PendingIntent.getBroadcast(context,0, imageview2Intent,0);   
remoteViews.setOnClickPendingIntent(R.id.widget_textview, pendingIntent); 

嘗試這種方式。

+0

這不行! –

+0

這實際上起作用,並且如果正確完成,則是正確的方法。 –