Consult experts! Why is my data displayed in the log, but only the last data is displayed in. settext?

Source: Internet
Author: User

=============== Problem description ====================


A function is provided to parse the JSON data of Baidu weather. gson resolution is used in results. Now the data displayed in the log has been parsed, but only the last one can be displayed on the textview interface. settext (). Why?
List<WeatherInfo.index> myIndex = weatherInfo.getIndex();for (index in : myIndex) {Log.i(TGA, "Des = " + in.getTipt() + ":" + in.getDes());indexContent.setText(in.getTipt() + ":" + in.getDes() + "\n");}

============= Solution 1 ======================


The text of textview is re-set every cycle, not the text of the last set ..

============= Solution 2 ======================


Get a stringbuffer as a global variable, append each time there is something new, and finally settext (buffer. tostring ())

However, we recommend that you use listview to parse the data you have read and then use the adapter to display it.

============= Solution 3 ======================


The third floor method can be changed as follows: String STR = "";
For (index in: myindex ){
STR + = (in. gettipt () + ":" + in. getdes () + "\ n ");
}
Indexcontent. settext (STR );

Consult experts! Why is my data displayed in the log, but only the last data is displayed in. settext?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.