我如何从服务内部将TextView和ProgressBar设置为它们的findViewById视图?

 ProgressBar dialog;

TextView Titletext;


@Override
public IBinder onBind(Intent intent) {
    // TODO Auto-generated method stub
    return null;
}
@Override
public void onCreate(){
    super.onCreate();
    Log.e("StackWidgetService", "Inside of onCreate in Widget Service");

    getter fethcer = new getter();
    fethcer.execute();

}

最佳答案

只需获取对AppWidgetManager的引用并更新布局。

AppWidgetManager awm = AppWidgetManager.getInstance(context);
int[] appWidgetIds = awm.getAppWidgetIds(yourProviderComponentName);
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.thelayout);
// Construct the remote views here ...

awm.updateAppWidget(appWidgetIds[0], rv);


此示例仅更新第一个窗口小部件实例(appWidgetIds[0])的布局,如果没有窗口小部件,则可能甚至崩溃。通常,您必须遍历appWidgetIds数组并分别更新每个数组。或如果没有小部件实例,则跳过循环。

08-18 18:47