1

I have an ArrayList of TextViews of a fixed size X.

I want to set the text of the TextViews based on a smaller ArrayList of Strings.

The remaining ArrayList TextViews I want them to have e.g a dash

How I am going to accomplish this with following way?

for(int i = 0; i<TotalList.size();i++)
{
    TotalList.get(i).setText(SmallerList.get(a).toString());
    a++;       
}

5 Answers 5

1
// iterate over smaller list 
for(int i = 0; i < SmallerList.size(); i++) {
    TotalList.get(i).setText(SmallerList.get(i));    
}

// set remaining items
for (int i = SmallerList.size(); i < TotalList.size(); i++) {
    TotalList.get(i).setText("---");
}
Sign up to request clarification or add additional context in comments.

Comments

0
for(int i = 0; i < smallList.size(); i++) {
    totalList.get(i).setText(smallList.get(i));
}

3 Comments

The Smaller list is ArrayList<String> and the TotalList is TotalList<TextView>
@MiaoulisNikos sorry, misunderstood the question, fixed it
Thanks for your submission to StackOverflow! Could you please add some text explanation for why this solves the problem? This will help future readers who might experience the same, or similar issues.
0

something like this ?

int size = smallerList.size();
for(int i = 0; i<TotalList.size();i++)
{
    TextView tv=new TextView(getApplicationContext());
    if(i <size){
        tv.get(i).setText(SmallerList.get(i).toString());
    }else{
        tv.get(i).setText("-"); 
}

Comments

0

You can do something like this:

for(int i = 0; i<TotalList.size();i++){
    if(i < SmallerList.size()){
        TotalList.get(i).setText(SmallerList.get(i));
    }else{
        TotalList.get(i).setText("...");
    }
}

Comments

0

Use two for loops :

    for(int i = 0; i<SmallerList.size();i++)
    {
        TotalList.get(i).setText(SmallerList.get(i).toString());
    }

    for(int i = SmallerList.size(); i<TotalList.size();i++)
    {
        TotalList.get(i).setText("----------");      
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.