Skip to content

Instantly share code, notes, and snippets.

@akexorcist
Last active January 5, 2016 18:14
Show Gist options
  • Save akexorcist/4c2518a7e3e1afd4ee62 to your computer and use it in GitHub Desktop.
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
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());
}
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