Advertisement
Guest User

Untitled

a guest
Feb 8th, 2013
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. public class news extends ListActivity {
  2.  
  3.  
  4. @Override
  5. public void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7. new connection().execute();
  8. System.out.println("prova1");
  9. }
  10.  
  11. public class connection extends AsyncTask<Void, Void, HashMap<String,ArrayList<String>>> {
  12.  
  13. public HashMap<String,ArrayList<String>> doInBackground(Void... params) {
  14. HashMap<String,ArrayList<String>> temhashmap=new HashMap<String,ArrayList<String>>();
  15. ArrayList<String> titoli = new ArrayList<String>();
  16. ArrayList<String> descrizioni = new ArrayList<String>();
  17. System.out.println("prova2");
  18. // All static variables
  19. final String URL = "http://www.messedaglia.it/index.php/archivio-news?format=feed&type=rss";
  20. // XML node keys
  21. final String ITEM = "item"; // parent node
  22. final String TITLE = "title";
  23. final String DESC = "description";
  24. Element e = null;
  25. ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
  26.  
  27. XMLParser parser = new XMLParser();
  28. String xml = parser.getXmlFromUrl(URL); // getting XML
  29. Document doc = parser.getDomElement(xml); // getting DOM element
  30. NodeList nl = doc.getElementsByTagName(ITEM);
  31.  
  32. // looping through all item nodes <item>
  33. for (int i = 0; i < nl.getLength(); i++) {
  34. // creating new HashMap
  35. HashMap<String, String> map = new HashMap<String, String>();
  36. e = (Element) nl.item(i);
  37. // adding each child node to HashMap key => value
  38. map.put(TITLE, parser.getValue(e, TITLE));
  39. map.put(DESC, parser.getValue(e, DESC));
  40.  
  41. // adding HashList to ArrayList
  42. menuItems.add(map);
  43. }
  44. System.out.println("prova3");
  45. for (int c = 0; c < nl.getLength(); c++) {
  46. e = (Element) nl.item(c);
  47.  
  48. titoli.add(parser.getValue(e, TITLE));
  49. descrizioni.add(parser.getValue(e, DESC));
  50.  
  51. }
  52. temhashmap.put("titoli", titoli);
  53. temhashmap.put("descrizioni", descrizioni);
  54. return temhashmap;
  55. }
  56.  
  57. public void onPostExecute(HashMap<String,ArrayList<String>> resultmap) {
  58. System.out.println("prova4");
  59.  
  60. if(resultmap.size()>0){
  61. // get titoli ArrayList here
  62. ArrayList<String> titoli=resultmap.get("titoli");
  63. // get descrizioni ArrayList here
  64. ArrayList<String> descrizioni=resultmap.get("descrizioni");
  65. ArrayAdapter<String> adapter = new ArrayAdapter<String>(news.this,
  66. android.R.layout.simple_list_item_1, titoli);
  67. System.out.println("prova5");
  68. ListView listView = (ListView) news.this
  69. .findViewById(android.R.id.list);
  70. listView.setAdapter(adapter);
  71.  
  72. }
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement