Visible Android widget with ListView that cannot be clicked on ListItems

I'm having problems connecting the widget. The following code works partially. My widget shows a ListView with items. When you click on a widget where there is no element, "Intention" is displayed and the action begins. But when you click on the ListView Element, nothing happens.

Here is the code: WidgetProvicer:

public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) { for (final int iD : appWidgetIds) { final RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout .widget_layout); final Intent intent = new Intent(context, TickWidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, iD); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); remoteViews.setRemoteAdapter(R.id.WidgetItem, intent); remoteViews.setEmptyView(R.id.WidgetItem, R.id.empty_view); final Intent activityIntent = new Intent(context, MainActivity.class); final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, activityIntent, 0); remoteViews.setOnClickPendingIntent(R.id.Widget, pendingIntent); appWidgetManager.updateAppWidget(iD, remoteViews); appWidgetManager.notifyAppWidgetViewDataChanged(iD, R.id.WidgetItem); } super.onUpdate(context, appWidgetManager, appWidgetIds); } 

widget_layout.xml:

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/Widget" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ListView android:id="@+id/WidgetItem" android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="#D3D3D3" android:dividerHeight="1dp"/> <TextView android:id="@+id/empty_view" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/darker_gray" android:gravity="center" android:text="@string/emptytext" android:visibility="gone"/> </LinearLayout> 

ListViewItems has no buttons or anything else.

Thank you for your help!

+7
android android-intent android-activity android-listview widget
source share
1 answer

Finally it works:

in onUpdate profile:

 final Intent activityIntent = new Intent(context, MainActivity.class); final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, activityIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setPendingIntentTemplate(R.id.WidgetItem, pendingIntent); 

and in the ViewFactory view getViewAt:

 Bundle infos = new Bundle(); infos.putInt(TickWidgetProvider.WIDGET_LISTID, this.listId); final Intent activityIntent = new Intent(); activityIntent.putExtras(infos); remoteView.setOnClickFillInIntent(R.id.widgetListItemLayout, activityIntent); 

I don't know where I found it, but this example helped me get it to work: https://github.com/commonsguy/cw-advandroid/tree/master/AppWidget/LoremWidget

+3
source share

All Articles