eventClick
我正在开发一个用于显示联系人的 Android 小部件,但是当我单击联系人图像时无法创建。
例如,我使用 aStackRemoteViewsFactory
将联系人添加到我的GridView
.
这是我的代码:
public RemoteViews getViewAt(int position) {
Bitmap photo = loadContactPhoto(mContext.getContentResolver(), mWidgetItems.get(position).id);
RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.contact_item);
rv.setTextViewText(R.id.name, mWidgetItems.get(position).name);
if (photo != null) {
rv.setImageViewBitmap(R.id.image, photo);
}
final Intent fillInIntent = new Intent();
final Bundle extras = new Bundle();
extras.putLong(FavoriteContactsWidgetProvider.CONTACT_ID, mWidgetItems.get(position).id);
fillInIntent.putExtras(extras);
rv.setOnClickFillInIntent(R.id.contact_frame, fillInIntent);
return rv;
}
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int i = 0; i < appWidgetIds.length; ++i) {
final Intent intent = new Intent(context, FavoriteContactsWidgetService.class);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME)));
RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
rv.setRemoteAdapter(appWidgetIds[i], R.id.grid_view, intent);
final Intent onClickIntent = new Intent(context, FavoriteContactsWidgetProvider.class);
onClickIntent.setAction(FavoriteContactsWidgetProvider.CLICK_ACTION);
onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]);
onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME)));
final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(context, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT);
rv.setPendingIntentTemplate(R.id.image, onClickPendingIntent);
appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
}
super.onUpdate(context, appWidgetManager, appWidgetIds);
}
有人有一些想法来完成这项工作吗?