Android ListView in onClick widgets not working

I am trying to make the listrows in my ListView widget accessible using a method setOnClickFillInIntent

, but whenever I click the ListItem, nothing happens. 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 getView()

in my ViewFactory. Resource.WIDGET_PACKAGE contains my package name and just like any other key. The int position is a parameter getView()

. R.id.widget_layout_parent

is the parent layout for all 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 am missing or is there anything else you would like to know?

All help is appreciated! :)

+3


source to share


2 answers


When you call setPendingIntentTemplate(...)

, id

should be one in the AdapterView (in this case a ListView). When you call setOnClickFillInIntent(...)

, id

it should be in the view root layout that you are already doing, if I read your original post.



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;
}

      

+19


source


The above answer from @karakuri works great.



Both SetPendingIntentTemplate and setOnClickFillInIntent must be used together. One will not work without the other.

+4


source







All Articles