setText没有更新

这是代码,我想在选择随机图像之后将TextText设置为Textview数组..它不会更新textVew。 我传递Context并查看我的其他活动的这个类的构造函数? 这是非活动类如何实现相同?

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 generated = new ArrayList(); 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; } } } } } 

如何设置文本视图?

对于遇到此问题的任何人,您可能必须将setText方法置于此内

  ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { ((EditText)editText).setText(text); } }); 

你应该 setText(...) 之后调用postInvalidate() setText(...) ,而不是提前!

  ... _HudTextDisplay[i].setText(_hiddenObjects[i].getTag().toString()); _HudTextDisplay[i].postInvalidate(); ...