【发布时间】:2012-06-07 09:29:48
【问题描述】:
我在资源文件夹中有 200 张图片,我将它们命名为 name_1.png,name_2.png。我有一个数组,其中有几个数字,例如2, 4 , 6 ,30 , 40 ... and so on。
我想将图像和文本视图加载到 android listview 并根据资源文件夹中的编号显示图像。
为此,我为custom list view 创建了activity class 和image adapter class。
我可以根据数组数据编号显示text view 数据,但不能显示图像。
谁能建议我如何做到这一点。我在想我必须在getview 方法中编写代码来更改图像。
这是我尝试过的getview 方法
@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;
}
【问题讨论】:
-
在资源文件夹中的意思是
res/drawable/对吗? -
请制作图片的int数组。
-
好吧,dipak先生,请您用一些代码告诉您如何做到这一点,这将是很大的帮助先生
-
对于 res 文件夹下的图像,我已经向您展示了解决方案检查
标签: java android android-listview