可点击的ListView Android小部件

时间:2019-02-15 01:05:45

标签: android android-intent android-listview android-widget

我正在尝试制作一个可点击的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 )的意图中。

0 个答案:

没有答案