I have a widget(which works) with a GridView, which shows information in 1 or more columns/rows. I want to set the number of columns programmatically, cause the users shall choose. If I set the numColumns inside the Layout-XML to "1", it works fine. If I try to set the numColumns in the following way, it has no effect:
rViews.setInt(R.id.duration_view, "setNumColumns", 1);
Layout looks like this:
<GridView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/duration_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="64dp"
android:verticalSpacing="0dp"
android:columnWidth="192dp"
android:numColumns="auto_fit"
/>
My widget onUpdate() method, using the RemoteAdapter:
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// ....
Intent intent = new Intent(context, ViewFlipperWidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
RemoteViews rViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
rViews.setRemoteAdapter(R.id.duration_view, intent);
rViews.setEmptyView(R.id.duration_view, R.id.empty_view);
// This doesnt have any effect...:-(
rViews.setInt(R.id.duration_view, "setNumColumns", 1);
appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.duration_view);
AppWidgetManager.getInstance(context).updateAppWidget(appWidgetId, rViews);
// ....
super.onUpdate(context, appWidgetManager, appWidgetIds);
Not only the setNumColumns has no effect, other method calls as well. What I'm doing wrong?