如何显示在android的网格视图中选择图像 [英] How to show a selection of image in grid view in android

查看:143
本文介绍了如何显示在android的网格视图中选择图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
  <一href=\"http://stackoverflow.com/questions/8643547/how-can-i-show-selection-of-an-image-in-grid-view-at-once\">how我可以显示网格视图图像选择一次

我有我想要一个复选标记图像的问题表明,当我们从图像的中间网格视图中选择一个图像,当我们点击一​​个网格项目,然后复选标记图像将显示在中间的指假设其中显示图像的选择的图像。

I have a question that I want a check mark image shows when we select an image from grid view in the middle of the image, means suppose when we click on a grid item then a check mark image will appear in the middle of the image which shows the selection of image.

例如下面都显示在iPhone屏幕:

For Example below are showing the iphone screen:

推荐答案

我能够通过使最终位置并添加一个onClick监听器的ImageView来获得点击图像的位置。该记录被点击的图像的位置。

I was able to get the position of the clicked image by making the position final and adding an onClick listener to the imageView. This logs the position of the image that was clicked.

@Override
public View getView(final 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);


    imageView.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View view) {
        Log.d("onClick","position ["+position+"]");
      }

    });

  } 
  else {
    imageView = (ImageView) convertView;
  }

  imageView.setImageResource(mThumbIds[position]);
  return imageView;
}



或使用本:

对于一个GridView可以使用setOnItemClickListener方法有一个OnItemClickListener监听器。该侦听器会给你,你必须签字覆盖方法


or use this :
For a GridView you can use the setOnItemClickListener method to have an OnItemClickListener listener. That listener will give you a method that you must override with the signature

onItemClick(AdapterView<?> parent, View v, int position, long id)

你在哪里得到的项目中单击的网格和认为是网格的单元格内的位置。这就是你需要什么?

where you get the position of the item in the grid that was clicked and the View that is inside the cell of the grid. Is that what you need?

这篇关于如何显示在android的网格视图中选择图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆