Here is the code and i want to setText the Array of Textview after the random Images selected.. its not updating the textVew. I am passing Context and view to the constructor of this class of my other activity ? this is non activity class how to achieve the same?
public class DisplayObject {
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
};
static View[] _hiddenObjects;
int NO_OF_OBJECTS = 15;
TextView[] _HudTextDisplay = new TextView[7];
public HiddenObject(Context context, View v) {
// TODO Auto-generated constructor stub
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View huddisplay = inflater.inflate(R.layout.gameplay, null);
/*NO_OF_OBJECTS = context.getResources().getInteger(R.integer.NO_OF_OBJECTS_AVAILABLE_PER_LEVEL);*/
_hiddenObjects = new View[NO_OF_OBJECTS];
random();
for (int i = 0; i < hudDisplay.length; ++i) {
_HudTextDisplay[i] = (TextView) huddisplay.findViewById(hudDisplay[i]);
_HudTextDisplay[i].setText(_hiddenObjects[i].getTag().toString());
}
}
public void random() {
List<Integer> generated = new ArrayList<Integer>();
for (int i = 0; i < NO_OF_OBJECTS; ++i) {
while (true) {
Integer next = _randomGenerator.nextInt(GamePlayActivity._hiddenObjects.length);
if (!generated.contains(next)) {
_hiddenObjects[i] = GamePlayActivity._hiddenObjects[next];
Log.d("Check", "Image is " + _hiddenObjects[i].getTag());
generated.add(next);
break;
}
}
}
}
}
how to setText the textview ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…