Last active
January 5, 2016 18:14
-
-
Save akexorcist/4c2518a7e3e1afd4ee62 to your computer and use it in GitHub Desktop.
The answer of someone's question in android developer facebook group https://goo.gl/SHVv7Z
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String data = "<b>อุณหภูมิ : </b>29.7 องศาเซลเซียส <br />\n" + | |
"<b>ความชื้นสัมพัทธ์ : </b> 67 % <br />\n" + | |
"<b>ความกดอากาศ : </b> 1011.08 มิลลิบาร์ <br /> \n" + | |
"<b>ทิศทางลม : </b> ทิศตะวันตกค่อนไปทางเหนือ <b>ความเร็ว </b> 7.4 กม./ชม.<br /> \n" + | |
"<b>ทัศนวิสัย : </b> 10.0 กิโลเมตร <br />\n" + | |
"<b>ลักษณะอากาศ : </b> มีเมฆบางส่วน <br />\n" + | |
"<b>ฝนสะสมวันนี้ : </b> 0.0 มิลลิเมตร <br/>\n" + | |
"<b>พระอาทิตย์ขึ้นเช้าพรุ่งนี้: </b>06:41 น. <br />\n" + | |
"<b>พระอาทิตย์ตกเย็นวันนี้: </b>18:23 น."; | |
ArrayList<WeatherData> weatherDataList = new ArrayList<>(); | |
data = Html.fromHtml(data).toString(); | |
String[] dataList = data.split("\n"); | |
for (String dataItem : dataList) { | |
String[] newData = dataItem.split(": "); | |
if (newData.length == 2) { | |
String title = newData[0].trim(); | |
String value = newData[1].trim(); | |
WeatherData weatherData = new WeatherData(title, value); | |
weatherDataList.add(weatherData); | |
} | |
} | |
// เอา weatherDataList ไปใช้งาน | |
for (WeatherData weatherData : weatherDataList) { | |
Log.e("Check", weatherData.getTitle() + " : " + weatherData.getValue()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class WeatherData { | |
String title; | |
String value; | |
public WeatherData(String title, String value) { | |
this.title = title; | |
this.value = value; | |
} | |
public String getTitle() { | |
return title; | |
} | |
public String getValue() { | |
return value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment