我如何知道或捕获 ImageView onclicklistener?
public class AppWidget extends AppWidgetProvider{
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i=0; i<N; i++) {
int appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, ShowActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
views.setOnClickPendingIntent(R.id.imageView1, pendingIntent);
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
}
在上面的编码中,当点击 ImageView 时,intent 到 ShowActivity.class。但我真正想要的是当单击 ImageView 时,我想显示“Toast”消息而不进行任何活动。