Issue
Have been attempting different approaches to implement an onClick event for the ListView in my widget but with no avail.
My widget is defined in the AndroidManifest.xml:
<!-- Widget -->
<receiver android:name=".widget.AppWidgetProvider">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/app_widget_info"/>
</receiver>
<service android:exported="false" android:name=".widget.AppWidgetService" android:permission="android.permission.BIND_REMOTEVIEWS"/>
My first approach was to use onReceive for receiving the intent and start a different activity:
// setPendingIntentTemplate in AppWidgetProvider
final Intent onClickIntent = new Intent(context, AppWidgetProvider.class);
onClickIntent.setAction(AppWidgetProvider.CLICK_ACTION);
onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME)));
final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(context, 0,
onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
rv.setPendingIntentTemplate(R.id.widget_schedule_list, onClickPendingIntent);
// and setOnClickFillInIntent in the getViewAt() in RemoteViewsService.RemoteViewsFactory class
final Bundle extras = new Bundle();
final Intent fillInIntent = new Intent();
extras.putInt(TVTracWidgetProvider.EXTRA_ITEM, position);
fillInIntent.putExtras(extras);
rv.setOnClickFillInIntent(R.id.episode_schedule_widget_row, fillInIntent);
My second approach was to start the activity directly:
// setPendingIntentTemplate in AppWidgetProvider
TaskStackBuilder builder = TaskStackBuilder.create(context)
.addNextIntent(new Intent(context, MainActivity_.class));
builder.addNextIntent(new Intent(context, EpisodeActivity_.class));
rv.setPendingIntentTemplate(R.id.widget_schedule_list, builder.getPendingIntent(1, PendingIntent.FLAG_UPDATE_CURRENT));
// and setOnClickFillInIntent in RemoteViewsFactory getViewAt()
Bundle extras = new Bundle();
extras.putInt(EpisodeActivity.showIdExtra, episode.getShow().getId());
extras.putInt(EpisodeActivity.seasonNrExtra, episode.getSeasonNr());
extras.putInt(EpisodeActivity.episodeNrExtra, episode.getEpisodeNr());
Intent fillInIntent = new Intent();
fillInIntent.putExtras(extras);
rv.setOnClickFillInIntent(R.id.episode_schedule_widget_row, fillInIntent);
However, neither approach seems to work. The pendingIntentTemplate is on the ListView's id and onClickFillInIntent on the parent layout of each row item. Could anyone explain me what could cause the click not to be fired? Thanks in advance!
Sources: weatherlistwidget and App Widgets
Solution
Problem was the TextViews inside the item which had textIsSelectable="true".
Answered By - LordOfBones
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.