Tiện ích của tôi bao gồm hai bố cục tương đối. Tôi đã thực hiện cả hai bố cục có thể nhấp. Sau đây là id của bố cục:Thay đổi hiển thị tiện ích con trên nhấp chuột
android:id="@+id/upper_layout"
android:id="@+id/bottom_layout"
Bây giờ, điều tôi cần là nếu người dùng nhấp vào upper_layout, bottom_layout sẽ ẩn.
Đây là những gì tôi đã thử cho đến nay nhưng nó không hoạt động. Bạn có thể kiểm tra những gì tôi đang làm sai? Hoặc có thể đề xuất một số cách khác để đạt được điều này.
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);
}
}