Question

I'm trying to make the listrows in my ListView Widget clickable by using the setOnClickFillInIntent method but whenever I click a ListItem nothing happends. Here are some key parts of my code:

Intent i = new Intent();
Bundle extras = new Bundle();

extras.putInt(Resource.WIDGET_PACKAGE, position);
i.putExtras(extras);
row.setOnClickFillInIntent(R.id.widget_layout_parent, i);

This is at the end of getView() in my ViewFactory. Resource.WIDGET_PACKAGE contains my package name and is just like any other key. The position int is from the getView() parameters. R.id.widget_layout_parent is the parent layout in all of the list items.

Here's the end of my WidgetProviders onUpdate()

Intent clickIntent = new Intent(context, ItemListActivity.class);

PendingIntent clickPI = PendingIntent.getActivity(context, 0,
        clickIntent, PendingIntent.FLAG_UPDATE_CURRENT);

widget.setPendingIntentTemplate(R.id.widget_layout_parent, clickPI);

appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds[i],
        R.id.widget_list_view);

Is there something I'm missing or is there anything else you'd like to know?

All help is appreciated! :)

Was it helpful?

Solution

When you call setPendingIntentTemplate(...), the id should be that of the AdapterView (in this case the ListView). When you call setOnClickFillInIntent(...), the id should be that of the root View of the item layout, whcih is what you are already doing if I read your original post correctly.

public void onUpdate(Context context, AppWidgetManager manager, int[] appWidgetIds) {
    /* ... */
    widget.setPendingIntentTemplate(R.id.appwidget_listview, clickPI);
    /* ... */
}

public RemoteViews getViewAt(int position) {
    /* ... */
    row.setOnClickFillInIntent(R.id.widget_layout_parent, intent);
    /* ... */
    return row;
}

OTHER TIPS

Above answer by @karakuri works perfect.

Both setPendingIntentTemplate and setOnClickFillInIntent must be used together. One won't work without the other.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top