Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RemoteViews setViewVisibility on Android Widget

In my AppWidgetProvider, I do following:

@Override
public void onReceive(Context ctx, Intent intent) {
    final String action = intent.getAction();
    if (action.equals(NEXTPAGE_ACTION)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(ctx);
        RemoteViews rv = new RemoteViews(ctx.getPackageName(), R.layout.widget_layout);
        rv.setViewVisibility(R.id.page1, View.GONE);
        rv.setViewVisibility(R.id.page2, View.VISIBLE);
    final int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    appWidgetManager.updateAppWidget(appWidgetId, rv);
    }
}

Although I'm updating the layout via updateAppWidget, the change is not really reflected on the UI. What could be possibly going wrong? Thanks much!

like image 208
trigger Avatar asked Feb 05 '12 23:02

trigger


People also ask

What is remote view in Android?

“RemoteView controls PC from a mobile device such as a smartphone, as well as control Android device from a PC or mobile. “


1 Answers

Have you tried using INVISIBLE and not GONE? Gone will remove the view as if it were never there. And invisible will hold the view's place in the layout, but make it invisible.

 rv.setViewVisibility(R.id.page1, View. INVISIBLE);
like image 96
AndroidKen Avatar answered Sep 29 '22 10:09

AndroidKen