我在本教程中的 GridView 中显示了图像。我希望能够单击单个图像并执行其他事件,并且我需要知道单击了哪个图像。
我必须在 ImageAdapter 类中添加 imageView.onKeyDown(keyCode, event) 吗?这是当前存在的代码:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
// if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
//does this need imageView.onKeyDown(keyCode, event)?
}
else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
它将如何指示单击了哪个图像?如何创建正确的处理程序?