首页 > 解决方案 > 以编程方式添加的 RemoteViews 按钮应通过单击 android 打开活动

问题描述

我以编程方式向 LinearLayout 添加了一个按钮,我想让它可以点击以打开活动:

按钮是这样创建的:

RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.android_app_widget);
RemoteViews media = new RemoteViews(context.getPackageName(), R.layout.button_layout);
rv.addView(R.id.buttons_list, media);

如何使用setOnClickPendingIntent使RemoteViews 媒体可点击???

以编程方式将 TextViews 添加到主屏幕小部件

这只是解释如何以编程方式添加按钮/视图

我尝试使用这样的东西,但我没有 RemoteView 的任何 ID,因为它是通过编程方式创建的......

remoteviews.setOnClickPendingIntent(R.id.**i don't have a id**,
            getPendingSelfIntent(context, OPEN_APP));


protected PendingIntent getPendingSelfIntent(Context context, String action) {
    Intent intent = new Intent(context, getClass());
    intent.setAction(action);
    return PendingIntent.getBroadcast(context, 0, intent, 0);
}

标签: androidwidgetandroid-pendingintentprogrammaticallyremoteview

解决方案


推荐阅读