title: update widget with multiple layouts
body: <p>I have an app that need to change different layouts for widget, depending on size, for exemple if widget is 4x2 cells then set up widget_layout, esle set up widget_layout1.</p>
  
  <p>For this change I use @Gogu's <a href="https://stackoverflow.com/a/14301127/3595288">method</a>:</p>
  
  <pre><code>    @Override
  public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) {
  
      Log.d("widget", "Changed dimensions");
  
      // See the dimensions and
      Bundle options = appWidgetManager.getAppWidgetOptions(appWidgetId);
  
      // Get min width and height.
      int minWidth = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH);
      int minHeight = options.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT);
  
      // Obtain appropriate widget and update it.
      appWidgetManager.updateAppWidget(appWidgetId, getRemoteViews(context, minWidth, minHeight));
  
      super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions);
  }
  
  /**
   * Determine appropriate view based on width provided.
   *
   * @param minWidth
   * @param minHeight
   * @return
   */
  private RemoteViews getRemoteViews(Context context, int minWidth, int minHeight) {
  
      // First find out rows and columns based on width provided.
      int rows = getCellsForSize(minHeight);
      int columns = getCellsForSize(minWidth);
  
      Log.d("dinazaur coloane", "nr este: " + columns);
      Log.d("dinazaur randuri", "nr este: " + rows);
  
  
      if (columns == 4) {
          // Get 4 column widget remote view and return
          return new RemoteViews(context.getPackageName(),
                  R.layout.simple_widget);
      } else {
          // Get appropriate remote view.
          return new RemoteViews(context.getPackageName(),
                  R.layout.simple_widget2);
      }
  }
  
  /**
   * Returns number of cells needed for given size of the widget.
   *
   * @param size Widget size in dp.
   * @return Size in number of cells.
   */
  private static int getCellsForSize(int size) {
      return (int) (Math.ceil(size + 30d) / 70d);
  }
  </code></pre>
  
  <p>I can't understand why after changing widget layout size( get it bigger -> change to layout_simple1 and then smaller changing to layout_simple back ), <code>onUpdate()</code> method that handle onClick PendingIntent for layout_simple is not working any more (is not even called), the code is:</p>
  
  <pre><code>  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
      final int count = appWidgetIds.length;
  
      for (int i = 0; i &lt; count; i++) {
          int widgetId = appWidgetIds[i];
          String number = String.format("%03d", (new Random().nextInt(900) + 100));
  
          RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.simple_widget);
          remoteViews.setTextViewText(R.id.textView, number);
  
          Intent intent = new Intent(context, SimpleWidgetProvider.class);
          intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
          intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
  
          PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
          remoteViews.setOnClickPendingIntent(R.id.actionButton, pendingIntent);
          appWidgetManager.updateAppWidget(widgetId, remoteViews);
  
  
      }
  }
  </code></pre>
  
  <p>my widget xml is:</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:initialLayout="@layout/simple_widget"
      android:minHeight="60dp"
      android:minWidth="120dp"
      android:resizeMode="horizontal|vertical"
      android:updatePeriodMillis="1800000"
      android:widgetCategory="home_screen|keyguard"&gt;
  
  &lt;/appwidget-provider&gt;
  </code></pre>