title: How to set onClickListener on button inside Widget?
body: <p>I have tried to do according to this <a href="https://stackoverflow.com/a/23221007/2255924">solution</a>. But it is somehow not working.
  No errors, which may give clue how to solve.</p>
  
  <p>Inside my manifest, I have this receiver:</p>
  
  <pre><code>&lt;receiver android:name=".ImageReceiver"&gt;
      &lt;intent-filter&gt;
          &lt;action android:name="android.appwidget.action.APPWIDGET_UPDATE" /&gt;
      &lt;/intent-filter&gt;
      &lt;meta-data android:name="android.appwidget.provider"
          android:resource="@xml/widget_image" /&gt;
  &lt;/receiver&gt;
  </code></pre>
  
  <p>widget_image.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
      android:minWidth="72dp"
      android:minHeight="72dp"
      android:updatePeriodMillis="1800000"
      android:initialLayout="@layout/widget_layout"&gt;
  &lt;/appwidget-provider&gt;
  </code></pre>
  
  <p>widget_layout.xml</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
      android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"&gt;
  
      &lt;ImageView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:id="@+id/ivImage"
          android:layout_alignParentTop="true"
          android:layout_alignParentLeft="true"
          android:layout_alignParentStart="true" /&gt;
  
      &lt;Button
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="New Button"
          android:id="@+id/bRefresh" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>ImageReceiver looks like this:</p>
  
  <pre><code>public class ImageReceiver extends AppWidgetProvider {
  
      public static final String REFRESH_BUTTON_CLICKED = "REFRESH_BUTTON_CLICKED";
  
      @Override
      public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
          super.onUpdate(context, appWidgetManager, appWidgetIds);
  
          RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
          remoteViews.setOnClickPendingIntent(R.id.bRefresh, getPendingSelfIntent(context, REFRESH_BUTTON_CLICKED));
      }
  
      @Override
      public void onReceive(Context context, Intent intent) {
          super.onReceive(context, intent);
  
          if (REFRESH_BUTTON_CLICKED.equals(intent.getAction())) {
              Toast.makeText(context, "Button click", Toast.LENGTH_LONG).show();
          }
  
      }
  
      protected PendingIntent getPendingSelfIntent(Context context, String action) {
          Intent intent = new Intent(context, getClass());
          intent.setAction(action);
          return PendingIntent.getBroadcast(context, 0, intent, 0);
      }
  }
  </code></pre>
  
  <p>When I click Button bRefresh, it should show Toast "Button click" but it is not showing. How to solve this problem?</p>