Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/195.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何对imageView使用setId()_Android - Fatal编程技术网

Android 如何对imageView使用setId()

Android 如何对imageView使用setId(),android,Android,我在GridViewAdapter类中创建了一个imageView: @Override public View getView(int position, View convertView, ViewGroup parent) { // Try to reuse the views ImageView view = (ImageView) convertView; boolean checked = (mCheckBox==null)?false:(((CheckBox

我在GridViewAdapter类中创建了一个imageView:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Try to reuse the views
    ImageView view = (ImageView) convertView;
    boolean checked = (mCheckBox==null)?false:(((CheckBox)  mCheckBox).isChecked());
    // if convert view is null then create a new instance else reuse it
    if (view == null) {
        view = new ImageView(Context);
        //view.setTag(ViewId(), "imageViewGRID");
        view.setId(R.id.1);
        Log.d("GridViewAdapter", "new imageView added");
    }
但我不确定如何使用.setId,以便在此行的另一个类中使用此imageView:

ImageView imageView1 = (ImageView)v.findViewById(R.id.1);
有人能解释一下这是怎么回事吗

请注意,我也尝试过:

view.setTag("imageView4Grid");

但是我得到一个错误,请检查此链接:

从API 17及以后,
View
class引入了静态方法
generateViewId()
,该方法将生成一个适合在
setId(int)
中使用的值

setId(int-id)
simlpy将正整数作为输入。
您正在尝试从资源获取id。这就是您要做的:

是的,所以我创建了一个带有id的xml文件,然后每当我在一个类中设置id,然后在另一个类中尝试获取该视图时,它总是返回null。我问了一个问题,但到目前为止,一个试图回答这个问题的人没有对任何反馈做出回应。谢谢你的链接!
ImageView imageView1 = (ImageView)v.findViewWithTag("imageView4Grid");