Mój widget składa się z dwóch względnych układów. Połączyłem oba układy. Poniżej przedstawiono ID w układzie:Zmiana widoczności widżetu na kliknięcie
android:id="@+id/upper_layout"
android:id="@+id/bottom_layout"
Teraz, co potrzebne jest, że jeśli użytkownik kliknie na upper_layout, bottom_layout powinny być niewidoczne.
Oto, co próbowałem do tej pory, ale to nie działa. Czy możesz sprawdzić, co robię źle? A może sugerują inne sposoby osiągnięcia tego.
Kod:
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);
}
}