headlines = new ArrayList(); links = new ArrayList(); try { URL url = new URL("http://www.bangkokbiznews.com/home/services/rss/home.xml"); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(false); XmlPullParser xpp = factory.newPullParser(); // We will get the XML from an input stream xpp.setInput(getInputStream(url), "UTF_8"); boolean insideItem = false; // Returns the type of current event: START_TAG, END_TAG, etc.. int eventType = xpp.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { if (xpp.getName().equalsIgnoreCase("item")) { insideItem = true; } else if (xpp.getName().equalsIgnoreCase("title")) { if (insideItem) headlines.add(xpp.nextText()); //extract the headline } else if (xpp.getName().equalsIgnoreCase("link")) { if (insideItem) links.add(xpp.nextText()); //extract the link of article } }else if(eventType==XmlPullParser.END_TAG && xpp.getName().equalsIgnoreCase("item")){ insideItem=false; } eventType = xpp.next(); //move to next element } } catch (MalformedURLException e) { e.printStackTrace(); } catch (XmlPullParserException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } // Binding data ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, headlines); setListAdapter(adapter); } protected void onListItemClick(ListView l, View v, int position, long id) { Uri uri = Uri.parse((String) links.get(position)); Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } private InputStream getInputStream(URL url) { try { return url.openConnection().getInputStream(); } catch (IOException e) { return null; }
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง