为什么小部件不更新以及如何将图像按钮设置为选中
Why isn't the widget updating and how to set an imagebutton as selected
XML:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="294dp"
android:minHeight="72dp"
android:updatePeriodMillis="1"
android:initialLayout="@layout/activity_widget" >
</appwidget-provider>
代码:
...
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
Log.i("ExampleWidget", "Updating widgets " + Arrays.asList(appWidgetIds));
// Perform this loop procedure for each App Widget that belongs to this
// provider
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
int k, p;
k = 0;
Log.d("Current SYSTEM", k+"");
}
appWidgetManager.updateAppWidget(appWidgetId, views); //even though it is being called here, the function itself is greyed out, stating the method is never used.
}
...
//this function is greyed out stating, this method is never used... how come?
public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.activity_widget);
appWidgetManager.updateAppWidget(appWidgetId, updateViews);
Log.d("UPDATED", "testing");
}
当我将小部件添加到主屏幕时,我看到 Log
,但即使我将 updatePeriodMillis
设置为 1,Log
也不再显示(除非我删除小部件并重新添加它)。
如何根据 updatePeriodMillis
显示 Log
我的第二期:
我在 Activity 中有以下内容:
if (int u <= 0) {
imageButton1.setSelected(true);
ImageButton2.setSelected(false);
}
如何在 Widget 中模仿相同的内容。
该函数显示为灰色,因为您正在调用该方法的重载版本,请仔细检查您传递的参数
appWidgetManager.updateAppWidget(appWidgetId, views);
和
updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId)
更精准的提示
appWidgetId, views
不同于 Context context, AppWidgetManager appWidgetManager, int appWidgetId
XML:
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="294dp"
android:minHeight="72dp"
android:updatePeriodMillis="1"
android:initialLayout="@layout/activity_widget" >
</appwidget-provider>
代码:
...
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
Log.i("ExampleWidget", "Updating widgets " + Arrays.asList(appWidgetIds));
// Perform this loop procedure for each App Widget that belongs to this
// provider
for (int i = 0; i < N; i++) {
int appWidgetId = appWidgetIds[i];
int k, p;
k = 0;
Log.d("Current SYSTEM", k+"");
}
appWidgetManager.updateAppWidget(appWidgetId, views); //even though it is being called here, the function itself is greyed out, stating the method is never used.
}
...
//this function is greyed out stating, this method is never used... how come?
public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
RemoteViews updateViews = new RemoteViews(context.getPackageName(), R.layout.activity_widget);
appWidgetManager.updateAppWidget(appWidgetId, updateViews);
Log.d("UPDATED", "testing");
}
当我将小部件添加到主屏幕时,我看到 Log
,但即使我将 updatePeriodMillis
设置为 1,Log
也不再显示(除非我删除小部件并重新添加它)。
如何根据 updatePeriodMillis
Log
我的第二期:
我在 Activity 中有以下内容:
if (int u <= 0) {
imageButton1.setSelected(true);
ImageButton2.setSelected(false);
}
如何在 Widget 中模仿相同的内容。
该函数显示为灰色,因为您正在调用该方法的重载版本,请仔细检查您传递的参数
appWidgetManager.updateAppWidget(appWidgetId, views);
和
updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId)
更精准的提示
appWidgetId, views
不同于 Context context, AppWidgetManager appWidgetManager, int appWidgetId