我有一个小部件,列表视图中包含两个文本(为了允许长文本滚动)。在应用程序运行的那一刻,当我单击它工作的小部件中的“刷新小部件”按钮时。但是,当应用程序未运行时,小部件的标题正在更新,而列表视图未更新。
这是我的代码
MyAppWidget.java
public class MyAppWidget extends AppWidgetProvider {
private static final String RELOAD_CLICKED = "MyAppWidget#btnReload";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// There may be multiple widgets active, so update all of them
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId, getClass());
}
}
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (RELOAD_CLICKED.equals(intent.getAction())) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
AppWidgetManager.INVALID_APPWIDGET_ID);
updateAppWidget(context, appWidgetManager, appWidgetId, getClass());
}
}
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager,
int appWidgetId, Class<?> cls) {
WidgetViewModel viewModel = DbManager.getInstance(context).getRandomWidget();
}
不负相思意
相关分类