2

I use the following code to update the text:

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setTextViewText(R.id.widget_counter, Long.toString(unreadRecordsCount));

but how can I hide it, if unreadRecordsCount = 0?

LA_
  • 19,823
  • 58
  • 172
  • 308

2 Answers2

5

Try this:

RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget);
views.setTextViewText(R.id.widget_counter, Long.toString(unreadRecordsCount));
if (unreadRecordsCount == 0) {
    views.setViewVisibility(R.id.widget_counter, View.INVISIBLE);
}
dave.c
  • 10,910
  • 5
  • 39
  • 62
1

I'm not totally familiar with RemoteViews but a quick check with the Android API gives this: RemoteView#setVisibility. I am assuming it works like a usual widget's setVisibility.

Zarah
  • 5,179
  • 2
  • 29
  • 29