1

我正在用每日记住单词制作字典,我想在小部件上显示它。当我更改下一个单词时,小部件不会更新。如何使小部件更新。请帮我!这是我的课:

public class HelloWidget extends AppWidgetProvider {
private SharedPreferences sharename, sharedescribed;
private SharedPreferences na, dess;



@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,int[] appWidgetIds) {
    final int N = appWidgetIds.length;

    for (int i = 0; i < N; i++)
    {
        int appWidgetId = appWidgetIds[i];

        SharedPreferences sharename = PreferenceManager.getDefaultSharedPreferences(context);
        String na = sharename.getString("thename", "null");


        SharedPreferences sharedescribed = PreferenceManager.getDefaultSharedPreferences(context);
        String dess = sharedescribed.getString("thedescribed", "null");


        RemoteViews views = new RemoteViews(context.getPackageName(),
                R.layout.main2);

        views.setTextViewText(R.id.widget_textview, na);
        views.setTextViewText(R.id.widget_textview2, dess);


        appWidgetManager.updateAppWidget(appWidgetId, views);
    }

    super.onUpdate(context, appWidgetManager, appWidgetIds);





}

}

4

0 回答 0