从View Array中随机选择ImageViews

时间:2012-03-07 06:04:04

标签: android

我试图从View数组中选择21中的Random 15 ImageViews,并希望将它们设置为Clickable,然后同样需要赋予TextView数组

这是代码..如何实现相同的

public class HiddenObject {

   Random _randomGenerator= new Random();
   int hudDisplay[]={R.id.HUD_Text_Element1,R.id.HUD_Text_Element2,R.id.HUD_Text_Element3,
                   R.id.HUD_Text_Element4,R.id.HUD_Text_Element5,R.id.HUD_Text_Element6,
                   R.id.HUD_Text_Element7};

   View[] _hudDisplay;
   View[] _hiddenObjects; 
   int NO_OF_OBJECTS;

   public HiddenObject(Context context,View v) {
           // TODO Auto-generated constructor stub


           View huddisplay= View.inflate(context, R.id.HUD_Display, null);

           _hudDisplay=GetView.getViewArrays(huddisplay, R.id.HUD_Display);


           NO_OF_OBJECTS=context.getResources().getInteger(R.integer.NO_OF_OBJECTS_AVAILABLE_PER_LEVEL);

           _hiddenObjects= new View[NO_OF_OBJECTS];

           random();

   }

   public void setHudDisplay()
   {



   }

   public void random(){

       for(int i=0;i<NO_OF_OBJECTS ;++i)
       {
           while(true)
           {
               Integer next = _randomGenerator.nextInt(GamePlayActivity._hiddenObjects.length);
               _hiddenObjects[i]=GamePlayActivity._hiddenObjects[next];
               Log.d("Print", "Image is " + _hiddenObjects[i].getContentDescription());
               if(!_hiddenObjects[i].isClickable()){
                   _hiddenObjects[i].setClickable(true);
                    break;
               }
           }

       }

   }

}

1 个答案:

答案 0 :(得分:0)

for循环你的HUDdisplay和_huddisplay [i] .setText(_hiddenObject [i] .getTag());