Since you are still creating a new String that is not very good and efficient, and that is the reason that you only have the last line.
So you do this:
-> get row -> add data to String -> setText
→ get next line → add data to String → setText
...
-> get the last line -> add data to String -> setText
and this is not very good. If you had milion strings in TABLE , you would have created milion String instances , and that's not very good, would you? Don't forget that String immutable and this kind of work is very expansive, so in such cases you need to use StringBuilder , which has methods that offer excellent performance with good performance against String .
StringBuilder builder = new StringBuilder(); for (Person p: person) { builder.append(p.getId() + " " + p.getName() + " " + p.getHotness() + " " + p.getAge()); } tv.setText(builder.toString());
Now he is doing the desired work.
source share