Android的布局,我想能够在我的布局环和文本添加到textviews动态,这并不会报错了,但我得到失去的行中的显示例如for循环文本
Tw04 One4
我想是能够显示
One1 Two1
One2 Two2
等等
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rel_layout);
for (int i = 0; i < 5; i++) {
TextView woTxt = (TextView) findViewById(R.id.ticker_price);
woTxt.setText("One"+i);
TextView cusTxt = (TextView) findViewById(R.id.ticker_symbol);
cusTxt.setText("Two"+i);
}
}
你应该在'for'循环之前获得对TextViews的引用,然后使用'for'循环中的引用。 'findViewById()'是一个相对昂贵的方法调用。在一个简单的例子中,像你发布的示例一样重要,但如果你的数据集很大,它可能开始成为一个问题。 – FoamyGuy