Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 如何获取图像资源名称大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
如何获取动态设置的imageview资源名称

这是图像适配器代码

public class ImageAdapter extends BaseAdapter {
  private Context mContext;

  public ImageAdapter(Context C) {
    mContext = c;
  }

  public int getCount() {
    return mThumbIds.length;
  }

  public Object getItem(int position) {
    return null;
  }

  public long getItemId(int position) {
    return 0;
  }

  // create a new ImageView for each item referenced by the Adapter
  public View getView(int position,View convertView,ViewGroup parent) {
    View v;

    if (convertView == null) { // if it's not recycled,initialize some
      // attributes

      LayoutInflater li = getLayoutInflater();
      v = li.inflate(R.layout.gridxml,null);
        imageView = (ImageView)v.findViewById(R.id.icon_imagE);

      imageView.setLayoutParams(new GridView.LayoutParams(85,85));
      //imageView.setScaleType(ImageView.ScaleType.CENTER_CROp);
      imageView.setPadding(5,5,5);
    } else {
      imageView = (ImageView) convertView;
  }

    imageView.setImageresource(mThumbIds[position]);
        imageView.setTag(mThumbIds[position]);

    System.out.println(mThumbIds[0]);
          System.out.println(mThumbIds[1]);
          System.out.println(mThumbIds[2]);
          System.out.println(mThumbIds[3]);
          System.out.println(mThumbIds[4]);
    return imageView;
  }

  // references to our images
  private Integer[] mThumbIds = { R.drawable.directory_xml,R.drawable.news_xml,R.drawable.calendar_xml,R.drawable.facilities_xml,R.drawable.employee_handbook_xml,R.drawable.setTings_xml };
}
}

解决方法

您可以使用setTag()和getTag()来设置或获取图像资源名称以及imgae

当您动态设置图像时,可以添加以下行以使用图像设置imageresource名称

imageView.setTag("image resource name");

如果要检索可以使用的图像资源名称

String imagename = (String) imageView.getTag();

大佬总结

以上是大佬教程为你收集整理的android – 如何获取图像资源名称全部内容,希望文章能够帮你解决android – 如何获取图像资源名称所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。