gpt4 book ai didi

安卓 : How can i settag for the images which are in gridview?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:28:10 26 4
gpt4 key购买 nike

谁能告诉我如何为 gridview 中的图像设置标签和获取标签。我写了下面的代码,但它不起作用。以下代码是否正确?

int jj=100;
for(int j=0;j<imageid.length;j++)//imageid is the array of drawable images
{
griview1.getChildAt(j).setTag(jj);
System.out.println(g.getChildAt(j).getTag());
}

这是我的 getView 方法

public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub

ImageView imv;
if(arg1!=null)
{
imv=(ImageView)arg1;
}
else
{
imv=new ImageView(cont);
imv.setLayoutParams(new GridView.LayoutParams(40,40));
imv.setScaleType(ScaleType.CENTER_CROP);
imv.setPadding(0,0,0,0);

}

}
imv.setImageResource(imageid[arg0]);
return imv;

最佳答案

只需在 getView 中设置您的标签

public View getView(int arg0, View arg1, ViewGroup arg2) {

if(arg1!=null)
{
ImageView imv = new ImageView(cont);
imv.setLayoutParams(new GridView.LayoutParams(40,40));
imv.setScaleType(ScaleType.CENTER_CROP);
imv.setPadding(0,0,0,0);

arg1 = imv;
}
arg1.setTag(arg0);
return arg1;
}

关于安卓 : How can i settag for the images which are in gridview?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13953201/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com