如何加载从资源中的文件夹图像变成ListView的机器人 [英] how to load images from resources folder into android listview
问题描述
我有一个200图像资源文件夹我命名他们为 name_1.png
, name_2.png
。我有一个数组中,我有几个数字,如 2,4,6,30,40 ...等等
。
我想加载图像与文本视图到安卓列表视图
,并根据从资源文件夹的数量显示图像。
为此,我创建了一个活动类
和图像适配器类
为自定义列表查看
。
我能够根据阵列数据的数字显示文本视图
数据,但没有图像。
任何一个可以建议我如何做到这一点。我想,我必须写在 getview
方法code改变形象。
这是我试过 getview
法
@覆盖
公共查看getView(INT位置,查看convertView,父母的ViewGroup){
convertView = mInflater.inflate(mViewResourceId,NULL);
TextView的TV1 =(TextView中)convertView.findViewById(R.id.tvtype);
TextView中TV2 =(TextView中)convertView.findViewById(R.id.tvnumber);
ImageView的I1 =(ImageView的)convertView.findViewById(R.id.ivlfirst);
// INT I =的Integer.parseInt(正常_+ mStrings.get(位置)+PNG);i1.setBackgroundResource(正常_+ mStrings.get(位置)+PNG);
tv1.setText(mStrings1.get(位置));
tv2.setText(mStrings.get(位置));
返回convertView;
}
需要一个整数数组
为 R.drawable.imageView1 .... ..200
,并通过它的价值如同
私人整数[] = Imgid {R.drawable.imageview1,...,200};
i1.setBackgroundResource(Imgid [J]);
I have a 200 images in resource folder i named them as name_1.png
,name_2.png
. and I have a array in that I have few numbers such as 2, 4 , 6 ,30 , 40 ... and so on
.
I want to load image and text view into android listview
and show the images according to the number from resource folder.
For this I have created a activity class
and image adapter class
for custom list view
.
I am able to show the text view
data but not the images according to the array data numbers .
can any one suggest me how to do this. I am thinking that I have to write code in getview
method to change the image.
This is getview
method that I tried
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = mInflater.inflate(mViewResourceId, null);
TextView tv1 = (TextView)convertView.findViewById(R.id.tvtype);
TextView tv2 = (TextView)convertView.findViewById(R.id.tvnumber);
ImageView i1= (ImageView)convertView.findViewById(R.id.ivlfirst);
//int i = Integer.parseInt("normal_"+mStrings.get(position)+".png");
i1.setBackgroundResource("normal_"+mStrings.get(position)+".png");
tv1.setText(mStrings1.get(position));
tv2.setText(mStrings.get(position));
return convertView;
}
Take One Integer array
for R.drawable.imageView1......200
and pass its value Like
private Integer[] Imgid = {R.drawable.imageview1,....,200 };
i1.setBackgroundResource(Imgid[j]);
这篇关于如何加载从资源中的文件夹图像变成ListView的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!