更改图像视图背景动态 [英] Changing image view background dynamically
问题描述
我有一个在我的布局了一套10 imageviews。我已经给了他们连续的ID也为
I have a a set of 10 imageviews in my layout. I have given them sequential id's also as
android:id="@+id/pb1"
android:id="@+id/pb2"
现在我要动态地改变背景。
Now I want to change background dynamically.
int totalPoi = listOfPOI.size();
int currentPoi = (j/totalPoi)*10;
for (i=1;i<=currentPoi;i++) {
imageview.setBackgroundResource(R.drawable.progressgreen);
}
现在里面的for循环我想动态设置图像视图背景。 I,E,如果currentpoi值是3,3图像视图背景应该有所改变。什么都时代的for循环遍历许多图像视图的背景应该有所改变。希望这个问题是清楚了吧。
Now inside the for loop I want to set the image view background dynamically. i,e if the currentpoi value is 3, background of 3 image views should be changed. What ever the times the for loop iterates that many image view's background should be changed. Hope the question is clear now.
请注意:我需要被设置为10的图像观点仅1图像progressgreen
Note : I have only 1 image progressgreen that need to be set to 10 image views
推荐答案
最后,我以下列方式这样做,
Finally I did this in the following way,
我把所有的ID的数组中为
I placed all the id's in the array as
INT [] = imageViews {R.id.pb1,R.id.pb2,
int[] imageViews = {R.id.pb1, R.id.pb2,
R.id.pb3,R.id.pb4,R.id.pb5,R.id.pb6,R.id.pb7,R.id.pb8,R.id.pb9,R.id.pb10 };
R.id.pb3,R.id.pb4,R.id.pb5,R.id.pb6,R.id.pb7,R.id.pb8,R.id.pb9,R.id.pb10};
Now,
int pindex = 0;
for (pindex; pindex <currentPoi; pindex++) {
ImageView img = (ImageView) findViewById(imageViews[pindex]) ;
img.setImageResource(R.drawable.progressgreen);
}
现在,我能够动态地改变图像。
Now, I am able to change the images dynamically.
@ goto10。感谢你的帮助。我将调试点看到了什么差错在我的身边。
@goto10. Thanks for your help. I will debug your point to see what went wrong in my side
这篇关于更改图像视图背景动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!