从小部件上的本地数据库更新数据

时间:2019-03-06 05:33:32

标签: android widget

我已经在Widget中创建了AdapterViewFlipper,并在RemoteViewsFactory类中使用本地数据库设置了多个数据。当我们打开应用程序时,当sql获取新数据时,数据将获得一次设置,但不会更新。

我需要在后台甚至刷新按钮上更新数据,请点击

    static void updateAppWidget(Context context,
                            AppWidgetManager appWidgetManager,
                            int appWidgetId) {
    Intent intent = new Intent(context, WidgetService.class);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
    intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
    RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.layout_widget);
    rv.setRemoteAdapter(appWidgetId, R.id.listViewWidget, intent);
    rv.setEmptyView(R.id.listViewWidget, R.id.empty_view);
    appWidgetManager.updateAppWidget(appWidgetId, rv);
}

在本地数据库列表中的remoteview服务中设置数据:-

@Override
public RemoteViews getViewAt(int position) {

    final RemoteViews remoteView = new RemoteViews(context.getPackageName(), R.layout.inflator_layout_widget);
    remoteView.setTextViewText(R.id.province_name, dataList.get(position).getNome_comune());
    remoteView.setTextViewText(R.id.province_sub_name, dataList.get(position).getNome_centralina());
    remoteView.setTextViewText(R.id.date, "Ultimo agg. " + dataList.get(position).getUltimo_aggiornamento());return remoteView;}

0 个答案:

没有答案