My widget consists two relative layouts. I have made both the layouts clickable. Following are the id's of the layout:
android:id="@+id/upper_layout"
android:id="@+id/bottom_layout"
Now, what I need is that if a user clicks on the upper_layout, bottom_layout should be invisible.
Here, is what I have tried so far but it's not working. Can u check what I am doing wrong? Or, maybe suggest some other ways to achieve this.
Code :
public class BobsWidget extends AppWidgetProvider {
public static String ACTION_WIDGET_RECEIVER = "Clicked";
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.main);
Intent active = new Intent(context, BobsWidget.class);
active.setAction(ACTION_WIDGET_RECEIVER);
PendingIntent actionPendingIntent = PendingIntent.getBroadcast(context,
0, active, 0);
remoteViews.setOnClickPendingIntent(R.id.upper_layout,
actionPendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
}
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
// check, if our Action was called
if (intent.getAction().equals(ACTION_WIDGET_RECEIVER)) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.main);
remoteViews.setViewVisibility(R.id.bottom_layout, View.INVISIBLE);
}
super.onReceive(context, intent);
}
}
You have several inbuilt widget features available in Anndroid 3.0 or more versions.Check this link
I think you forgot to update the widget. Have you tried something like this ?
remoteViews.setViewVisibility(R.id.bottom_layout, View.INVISIBLE);
final ComponentName provider = new ComponentName(context, this.getClass());
appWidgetManager.updateAppWidget(provider, views);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With