android - 以编程方式添加的 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 媒体可点击???
这只是解释如何以编程方式添加按钮/视图
我尝试使用这样的东西,但我没有 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);
}
解决方案
推荐阅读
- database - 恢复期间的 PostgreSQL 12 零大小 wal 归档日志问题
- javascript - 谷歌地图图标放置
- excel - 将数据从工作表 A 复制并转换到工作表 B
- machine-learning - 逻辑回归可视化
- python - 熊猫:合并两个数据框并在一列上取平均值
- python - 如何在 Django 项目中创建可填写和可保存的弹出表单?
- java - 泛型类型擦除和类型转换
- php - 谁能帮我充分利用这段代码(PHP、mysqli_stmt::get_result / mysqli_stmt::bind_result 和 mysqli_stmt::fetch
- spring - 每个堆叠事务是否使用单独的连接?
- python - Python/Django:通过 Concat() 过滤对象并按相同的连接排序