【发布时间】:2013-11-28 08:15:32
【问题描述】:
我通过引用this article 实现了布局更新动画。当我单击按钮 ui 更新时,它工作正常。现在我想自动化这个过程。这意味着自动更新ui。我在 for 循环中使用了处理程序来定期更新 ui,如下所示
for(int i = 0; i < 100; i++){
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
final ViewGroup newView = (ViewGroup) LayoutInflater.from(getApplicationContext()).inflate(
R.layout.list_item, containerGroup, false);
TextView tv = (TextView) newView.findViewById(android.R.id.text1);
tv.setText(RAVEMSGS[(int) (Math.random()*RAVEMSGS.length)]);
containerGroup.addView(newView,0);
}
},2000);
}
但这不起作用。如何为动画动态更新 ui?
注意:我只发布了我用来更新列表视图的代码的一部分,如果我使用按钮的 onclick 列表器调用它,这段代码就可以工作。
谢谢。
【问题讨论】:
标签: android android-layout android-intent android-listview