Search code examples
androidlayoutclicklistenerandroid-appwidget

add click listener to entire appwidget


I have an appwidget and I want to add a click listener on the entire appwidget layout, not only on TextView ecc. This is not working

remoteViews.setOnClickPendingIntent(R.layout.profile_widget_layout, pendingIntent);

How can I do?


Solution

  • You cannot use setOnClickPendingIntent() with a layout resource ID, only with a widget ID.

    All you need to do is assign an android:id attribute to your outermost container (e.g., RelativeLayout), then use setOnClickPendingIntent() with that android:id value.