Question

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

}

}
Était-ce utile?

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

Autres conseils

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

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

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top