Search code examples
androidbuttonwidgetsetonupdate

How to set Widget button visibility?


Hi first of all i'm sorry for my bad english. How to set RemoteViews .setViewVisibility? I want to hide widget button when i click on it. Here is my code. Thanks for help.

@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {

    final int N = appWidgetIds.length;
    for (int i = 0; i < N; i++){

        int appId = appWidgetIds[i];
      widget = new RemoteViews(context.getPackageName(), R.layout.widget_wyglad);
      Intent Tv = new Intent(context, client_widget.class);
      Tv.setAction(AKCJA);
      Tv.putExtra("test", AKCJA);
      PendingIntent ptv = PendingIntent.getBroadcast(context, 0, Tv, 0);
      widget.setOnClickPendingIntent(R.id.bt_wid_tv, ptv);
      appWidgetManager.updateAppWidget(appId, widget);
    }

  super.onUpdate(context, appWidgetManager, appWidgetIds);
}

@Override
public void onReceive(Context context, Intent intent) {

    Bundle extras = intent.getExtras();
    if (extras != null){

        widget.setViewVisibility(R.id.bt_wid_tv, View.GONE);

    }
    else {Log.d("ERR", "EXTRAS ELSE");}

    super.onReceive(context, intent);   

}

}

Solution

  • You have done everything right about making the view hidden. just include this in your code-

    In your onReceive method-

    if (intent.getAction().equals(AKCJA)) {
    widget.setViewVisibility(R.id.bt_wid_tv, View.GONE);
    }