2

我有一个小部件,当我按下它时会更新,但我想在小部件更新时显示一个进度轮。

//remove text      
        updateViews.setViewVisibility(R.id.widget_textview, View.GONE);
        updateViews.setViewVisibility(R.id.widget_dkk, View.GONE);

// show progress wheel

updateViews.setViewVisibility(R.id.widget_Pross, View.VISIBLE);



// task that take time are locatet here a GetHTTP function



//Show text again       
        updateViews.setViewVisibility(R.id.widget_textview, View.VISIBLE);
        updateViews.setViewVisibility(R.id.widget_dkk, View.VISIBLE);

// Remove progress wheel

   updateViews.setViewVisibility(R.id.widget_Pross, View.GONE);

所有这些都位于我的小部件更新类中:

public static RemoteViews buildUpdate(Context context) {

但是进度轮没有显示。这就像小部件只更新一次,因此在 GetHttp 中计算时不显示进度轮。

编辑:

// Remove rext and show progress wheel
    updateViews.setViewVisibility(R.id.widget_textview, View.GONE);
        updateViews.setViewVisibility(R.id.widget_dkk, View.GONE);
        updateViews.setViewVisibility(R.id.widget_Pross, View.VISIBLE);

    ComponentName thisWidget = new ComponentName(context, SaldoWidget.class);
    AppWidgetManager manager = AppWidgetManager.getInstance(context);
    manager.updateAppWidget(thisWidget, updateViews);


//    GetHttp code here / long computing task her

 //Show text and remove progress wheel 
 updateViews.setViewVisibility(R.id.widget_textview, View.VISIBLE);
            updateViews.setViewVisibility(R.id.widget_dkk, View.VISIBLE);
            updateViews.setViewVisibility(R.id.widget_Pross, View.GONE);
            manager.updateAppWidget(thisWidget, updateViews);
4

1 回答 1

3

AppWidgetManager.updateAppWidget()每次要更改布局时都必须调用。

这意味着您必须隐藏原始小部件视图并在RemoteViews. 之后,调用updateAppWidget()更改布局并显示进度条。然后执行你的下载任务。之后,用获取的数据填充视图,隐藏进度指示器并updateAppWidget()再次调用以将其更改回正常布局。

The name RemoteViews may make this a bit confusing at the start. It's actually not a bunch of Views that you can control remotely from your app. It's a group of views that you build up to your needs and then you give it to the AppWidgetManager to publish it.

于 2011-08-28T20:39:56.143 回答