setid android,android-如何将setId()用于imageView
我在GridViewAdapter類(lèi)中在此處創(chuàng)建了一個(gè)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,以便可以在此行的另一個(gè)類(lèi)中使用此imageView:
ImageView imageView1 = (ImageView)v.findViewById(R.id.1);
有人可以澄清一下它是如何工作的嗎?
請(qǐng)注意,我也嘗試過(guò):
view.setTag("imageView4Grid");
與
ImageView imageView1 = (ImageView)v.findViewWithTag("imageView4Grid");
但我得到一個(gè)錯(cuò)誤
解決方法:
從API 17開(kāi)始,View類(lèi)引入了靜態(tài)方法generateViewId(),該方法將生成適合在setId(int)中使用的值.
setId(int id)simlpy將正整數(shù)作為輸入.
您正在嘗試從資源中獲取ID.這是您正在嘗試做的事情:How to set Id of dynamic created layout?
標(biāo)簽:android
來(lái)源: https://codeday.me/bug/20191122/2058921.html
總結(jié)
以上是生活随笔為你收集整理的setid android,android-如何将setId()用于imageView的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: mysql 内联函数_C++之内联函数
- 下一篇: 2021届安徽高考成绩查询,安徽2021