是否可以在主屏幕上的应用小部件的列表视图中禁用某些项目?
现在我正在为列表视图使用PendingIntent模板,然后用fillIntent填充每行的意图。我要做的是当按下一个项目以及其他任何不带领的项目时,不显示选择器背景。在普通列表视图中,您可以使用isEnabled解决它,但RemoteViewsFactory中不存在。
我的AppWidgetProvider看起来像这样:
public class StreamsWidgetProvider extends AppWidgetProvider {
@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];
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
//set service for list view
Intent listIntent = new Intent(context, StreamsWidgetService.class);
listIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
listIntent.setData(Uri.parse(listIntent.toUri(Intent.URI_INTENT_SCHEME)));
views.setRemoteAdapter(R.id.streamItemsList, listIntent);
Intent intent = new Intent(context, StreamsWidgetProvider.class);
intent.setAction(ACTION_START_ACTIVITY);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
views.setPendingIntentTemplate(R.id.streamItemsList, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
}
这是在RemoteViewsService中实例化的RemoteViewsFactory,上面的appWidgetProvider连接到它。
private class StreamItemWidgetFactory implements RemoteViewsService.RemoteViewsFactory {
...
@Override
public RemoteViews getViewAt(int position) {
...
if(isEnabled) {
...
Intent intent = new Intent();
intent.putExtra(StreamsWidgetProvider.BROADCAST_PARAM_ITEM_ID, item.getId());
...
rv.setOnClickFillInIntent(R.id.streamItemRowId, intent);
}
...
return item;
}
...
}
是否可以获得与ListView适配器相同的功能?我可以以某种方式删除某些行的pendingIntent吗?