Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ListView in widget onClick not working

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! :)

like image 622
SweSnow Avatar asked Jan 28 '13 16:01

SweSnow


1 Answers

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;
}
like image 131
Karakuri Avatar answered Oct 04 '22 08:10

Karakuri