1

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);   

}

}
Gillven
  • 21
  • 1
  • 3

3 Answers3

4

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);
}
Naddy
  • 2,664
  • 6
  • 25
  • 38
  • I try both solutions and nothing happend. Should i try update widget after: widget.setViewVisibility(R.id.bt_wid_tv, View.GONE) – Gillven Jul 20 '13 at 22:33
  • yes..exactly..after changing the view always use this code- appWidgetManager.updateAppWidget(appId, widget); – Naddy Jul 21 '13 at 06:55
-1

Have you tried using INVISIBLE instead of 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.bt_wid_tv, View. INVISIBLE);
Ankit Aggarwal
  • 2,367
  • 24
  • 30
-2

Yeah it finally work, There's what i change:

int appId = appWidgetIds[i]; 

change to:

appId = appWidgetIds[i];

next i add static int appId:

public class client_widget extends AppWidgetProvider {

static int appId;

finally add this new AppWidgetManager and update line:

public void onReceive(Context context, Intent intent) {

AppWidgetManager newAppWidgetManager = AppWidgetManager.getInstance(context);

        if (intent.getAction().equals(AKCJA)) {
            AppWidgetManager nowy = AppWidgetManager.getInstance(context);

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

            newAppWidgetManager.updateAppWidget(appId, widget);

Thanks @Naddy

Gillven
  • 21
  • 1
  • 3