Android 一些 TextView 的 id 到数组并从中获取以分配文本

Android some TextView's id to array and fetch from that to assign text

我正在尝试将一些 TextView id 保存到数组中并使用 for loop 获取它以分配文本。或示例:

String[] other_stuff_items = other_soft.split(";");
int[] tvs ={
        R.id.tv_other_stuff_one,
        R.id.tv_other_stuff_two,
        R.id.tv_other_stuff_three
};
int[] ivs ={
        R.id.ix_other_stuff_one,
        R.id.ix_other_stuff_two,
        R.id.ix_other_stuff_three
};

将 TextView id 保存到数组后,我正在尝试使用 for loop

获取数组项
for( int i=0; i>other_stuff_items.length; i++){
    tvs[i].setText(items_one[0]);
    ivs[i].setText(items_one[1]);
}

在上一节中,我收到 .setText() 的错误并从数组 获取小部件如何解决此问题?谢谢

您需要先找到 Views:

Textview tv;

for( int i=0; i>other_stuff_items.length; i++){
    tv = (TextView) findViewById(tvs[i]);
    tv.setText(items_one[0]);
    // do the same thing for the ivs stuff
}