为什么小部件不更新?

时间:2013-03-01 14:01:59

标签: java android android-widget

我正在制作一个带有Daily Remember Word的字典,我想在小部件上显示它。当我改变下一个单词时,小部件不会更新。如何使小部件更新。请帮我!这是我的班级:

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);





}

}

0 个答案:

没有答案