2011-04-01 16 views
0

我已经为我的应用程序制作了一个小部件。 此应用程序使用数据库。 我想要做的事情: - 我现在可以在我的数据库中有多少桌子,我在这个小部件上显示这个数字,有可能吗?当我执行OnUpdate时如何在小部件上显示数字

目前,在我的onUpdate函数中,我计算了我的记录数,但是如何显示这个?

提前致谢。

关于。

西蒙

回答

0

确保您有TextView在你的小窗口的布局一个唯一的ID。然后在你的onUpdate方法有类似:

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { 
    String countValue = "0"; 
    // code to retrieve & populate the count value goes here 

    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); 
    views.setTextViewText(R.id.widgetData, countValue); 
    for (int i=0;i<appWidgetIds.length;i++){ 
     appWidgetManager.updateAppWidget(appWidgetIds[i], views); 
    } 
} 
+0

谢谢,它工作完美 – 2011-04-01 13:12:17

相关问题