点击不突出显示的Android应用小部件列表视图项

时间:2013-11-30 10:53:23

标签: android listview android-widget

我正在创建一个带有列表视图的app小部件。当我点击列表视图项时,它不突出显示。请帮忙。

这里的场景是,当我点击列表视图项时,窗口小部件底部会显示某些操作按钮。但由于该项目未突出显示,因此用户将不知道选择了哪个项目。

Provider.java

public void onUpdate(Context context, AppWidgetManager appWidgetManager,
        int[] appWidgetIds) {

    final int N = appWidgetIds.length;

    // Perform this loop procedure for each App Widget that belongs to this
    // provider
    for (int i = 0; i < N; i++) {
        int appWidgetId = appWidgetIds[i];

        // initializing widget layout
        RemoteViews remoteViews = new RemoteViews(
                context.getPackageName(), R.layout.widget_4_4_layout);

            Intent listIntent = new Intent(context,
                    Widget_4_4_Service.class);
            listIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID,
                    appWidgetId);
            listIntent.putExtra("dur", String.valueOf(duration));
            listIntent.setData(Uri.parse(listIntent
                    .toUri(Intent.URI_INTENT_SCHEME)));
            remoteViews.setRemoteAdapter(R.id.id_widget_task_list,
                    listIntent);

            Intent taskIntent = new Intent(context,
                    Widget_4_4_Provider.class);
            taskIntent.setAction("action");

            PendingIntent taskPendingIntent = PendingIntent.getBroadcast(
                    context, 3, taskIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            remoteViews.setPendingIntentTemplate(R.id.id_widget_task_list,
                    taskPendingIntent);

            }
}

Factory.java

public RemoteViews getViewAt(int pos) {
    RemoteViews remoteView = new RemoteViews(ctxt.getPackageName(),
            R.layout.custom_widget_list_view);
    TaskDO task = taskList.get(pos);
    remoteView
            .setTextViewText(R.id.id_widget_list_task_name, task.TaskName);

    Intent i = new Intent();
    i.putExtra("task", String.valueOf(task.TaskId));
    remoteView.setOnClickFillInIntent(R.id.id_widget_list_task_name, i);

    return remoteView;
}

0 个答案:

没有答案