我正在尝试制作一个可点击的listview android主屏幕小部件。当我尝试捕获Intent
函数中的onReceiver
时,没有问题发生
已经尝试用Intent
制作Bundle
来发送额外内容,但是不起作用。
RemoteViewFactory
public class ListRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {
private Context context;
private Cursor cursor;
private Intent intent;
public ListRemoteViewsFactory(Context context, Intent intent) {
this.context = context;
this.intent = intent;
}
@Override
public RemoteViews getViewAt(int position) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.list_item_widget);
cursor.moveToPosition(position);
int rowid = cursor.getInt(0);
if (cursor.getString(3).equals("1")) {
remoteViews.setInt(R.id.widget_list_image, "setBackgroundResource", R.drawable.ic_check_box_checked);
} else {
remoteViews.setInt(R.id.widget_list_image, "setBackgroundResource", R.drawable.ic_check_box_unchecked);
}
Bundle extra = new Bundle();
extra.putInt(ToDoTickWidget.ROWID, rowid);
Intent activityIntent = new Intent();
activityIntent.putExtras(extra);
remoteViews.setOnClickFillInIntent(R.id.widget_list_image, activityIntent);
return remoteViews;
}
}
WidgetProvider(仅在安装或启动应用程序时运行该功能)
@Override
public void onReceive(Context context, Intent intent) {
Log.d("debug", "onReceive");
super.onReceive(context, intent);
}
我需要了解意图,特别是将Extra
添加到与列表中单击的项目相对应的bundle
( rowid )的意图中。