我正在为从网站上抓取的图片构建图像查看器,该图片查看器的工作原理像一个超级按钮,现在唯一缺少的是使用户可以手动导航,而不仅是坐在那里并等待adapterviewflipper刷新。因此,我内置了两个用于导航的按钮。 AppWidgetProvider的代码如下:
public class CollectionWidget extends AppWidgetProvider {
private final String NEXT_SCENE = "NAV_NEXT";
private final String PREV_SCENE = "NAV_PREV";
void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main_widget);
views.setOnClickPendingIntent(R.id.navSceneNext, getPendingSelfIntent(context, NEXT_SCENE));
views.setOnClickPendingIntent(R.id.navScenePrevious, getPendingSelfIntent(context, PREV_SCENE));
try {
setRemoteAdapter(context, views);
} catch (URISyntaxException e) {
e.printStackTrace();
}
appWidgetManager.updateAppWidget(appWidgetId, views);
}
protected PendingIntent getPendingSelfIntent(Context context, String action) {
Intent intent = new Intent(context, getClass());
intent.setAction(action);
return PendingIntent.getBroadcast(context, 0, intent, 0);
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// There may be multiple widgets active, so update all of them
for (int appWidgetId : appWidgetIds) {
updateAppWidget(context, appWidgetManager, appWidgetId);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
@Override
public void onEnabled(Context context) {
// Enter relevant functionality for when the first widget is created
}
@Override
public void onDisabled(Context context) {
// Enter relevant functionality for when the last widget is disabled
}
@Override
public void onReceive(Context context, Intent intent)
{
super.onReceive(context, intent);
if (NEXT_SCENE.equals(intent.getAction())) {
}else if (PREV_SCENE.equals(intent.getAction())){
// PROBLEM
}
}
private static void setRemoteAdapter(Context context, @NonNull final RemoteViews views) throws URISyntaxException {
Intent serviceIntent = new Intent(context, WidgetService.class);
views.setRemoteAdapter(R.id.scenarioAdapterViewFlipper,serviceIntent);
}
}
通过按钮(R.id.navSceneNext / navScenePrevious)触发可以正常工作,但是从现在开始,我不知道如何触发翻转AdapterViewFlipper,因为我无法从onReceived方法内部影响它,至少到目前为止据我所知。
有人可以提出解决方案吗?