user4790312
user4790312

Reputation:

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

I am trying to save some TextView id's to array and fetch that with for loop to assign text. or example:

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
};

after saving TextView id's to array I'm trying to get array items with for loop

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

In this above section, I get error for .setText() and get widgets from array how to resolve this problem? thanks

Upvotes: 0

Views: 115

Answers (1)

sshashank124
sshashank124

Reputation: 32189

You need to first find the 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
}

Upvotes: 3

Related Questions