Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class news extends ListActivity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- new connection().execute();
- System.out.println("prova1");
- }
- public class connection extends AsyncTask<Void, Void, HashMap<String,ArrayList<String>>> {
- public HashMap<String,ArrayList<String>> doInBackground(Void... params) {
- HashMap<String,ArrayList<String>> temhashmap=new HashMap<String,ArrayList<String>>();
- ArrayList<String> titoli = new ArrayList<String>();
- ArrayList<String> descrizioni = new ArrayList<String>();
- System.out.println("prova2");
- // All static variables
- final String URL = "http://www.messedaglia.it/index.php/archivio-news?format=feed&type=rss";
- // XML node keys
- final String ITEM = "item"; // parent node
- final String TITLE = "title";
- final String DESC = "description";
- Element e = null;
- ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
- XMLParser parser = new XMLParser();
- String xml = parser.getXmlFromUrl(URL); // getting XML
- Document doc = parser.getDomElement(xml); // getting DOM element
- NodeList nl = doc.getElementsByTagName(ITEM);
- // looping through all item nodes <item>
- for (int i = 0; i < nl.getLength(); i++) {
- // creating new HashMap
- HashMap<String, String> map = new HashMap<String, String>();
- e = (Element) nl.item(i);
- // adding each child node to HashMap key => value
- map.put(TITLE, parser.getValue(e, TITLE));
- map.put(DESC, parser.getValue(e, DESC));
- // adding HashList to ArrayList
- menuItems.add(map);
- }
- System.out.println("prova3");
- for (int c = 0; c < nl.getLength(); c++) {
- e = (Element) nl.item(c);
- titoli.add(parser.getValue(e, TITLE));
- descrizioni.add(parser.getValue(e, DESC));
- }
- temhashmap.put("titoli", titoli);
- temhashmap.put("descrizioni", descrizioni);
- return temhashmap;
- }
- public void onPostExecute(HashMap<String,ArrayList<String>> resultmap) {
- System.out.println("prova4");
- if(resultmap.size()>0){
- // get titoli ArrayList here
- ArrayList<String> titoli=resultmap.get("titoli");
- // get descrizioni ArrayList here
- ArrayList<String> descrizioni=resultmap.get("descrizioni");
- ArrayAdapter<String> adapter = new ArrayAdapter<String>(news.this,
- android.R.layout.simple_list_item_1, titoli);
- System.out.println("prova5");
- ListView listView = (ListView) news.this
- .findViewById(android.R.id.list);
- listView.setAdapter(adapter);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement