Note that there are some explanatory texts on larger screens.

plurals
  1. PODisable list item in App Widget
    text
    copied!<p>Is it possible to have some items disabled in a list view in an app widget on the home screen?</p> <p>Right now I'm using a PendingIntent template for the list view and then I fill in the intents for each row with an fillIntent. What I'm trying to do is to not show the selector background when an item is pressed for titles and other sort of items that doesn't lead anywhere. In a normal list view you solve it by using <a href="http://developer.android.com/reference/android/widget/ListAdapter.html#isEnabled%28int%29" rel="nofollow">isEnabled</a> but it doesn't exist in the <a href="http://developer.android.com/reference/android/widget/RemoteViewsService.RemoteViewsFactory.html" rel="nofollow">RemoteViewsFactory</a>.</p> <p>My AppWidgetProvider looks like this:</p> <pre><code>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&lt;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); } } </code></pre> <p>Here is the RemoteViewsFactory that is instantiated in the RemoteViewsService which the above appWidgetProvider connects to.</p> <pre><code>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; } ... } </code></pre> <p>Is it possible to get the same functionality as a ListView Adapter? Can I in some way remove the pendingIntent for certain rows?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload