【发布时间】:2012-03-14 23:14:03
【问题描述】:
我的小部件包含两个相对布局。我已经使两个布局都可以点击。以下是布局的ID:
android:id="@+id/upper_layout"
android:id="@+id/bottom_layout"
现在,我需要的是,如果用户点击upper_layout,bottom_layout 应该是不可见的。
这是我迄今为止尝试过的,但它不起作用。你能检查我做错了什么吗? 或者,也许建议一些其他方法来实现这一点。
代码:
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);
}
}
【问题讨论】:
标签: android android-layout android-intent android-widget