2012-07-25 156 views
0

我在指向mp3音樂文件地址的URL中插入了一個xml文件,但我不知道如何下載此文件。從xml文件下載文件

這裏是我的代碼:

String xml = parser.getXmlFromUrl(URL); // getting XML from URL 
    Document doc = parser.getDomElement(xml); // getting DOM element 

    NodeList nl = doc.getElementsByTagName(KEY_SONG); 
    // looping through all song nodes <song> 
    for (int i = 0; i < nl.getLength(); i++) { 
     // creating new HashMap 
     HashMap<String, String> map = new HashMap<String, String>(); 
     Element e = (Element) nl.item(i); 
     // adding each child node to HashMap key => value 
     map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION)); 
     map.put(KEY_THUMB_URL, parser.getValue(e, KEY_THUMB_URL)); 
     map.put(KEY_URL, parser.getValue(e, KEY_URL)); 
     // adding HashList to ArrayList 
     songsList.add(map); 
    } 


    list=(ListView)findViewById(R.id.list); 

    // Getting adapter by passing xml data ArrayList 
    adapter=new LazyAdapter(this, songsList);   
    list.setAdapter(adapter); 


    // Click event for single list row 
    list.setOnItemClickListener(new OnItemClickListener() { 

     public void onItemClick(AdapterView<?> parent, View view, 
       int position, long id) { 




     } 
    }); 

應該是什麼onItemClick的代碼?

這段代碼是從xml中獲取鏈接並從此方法下載的代碼是什麼?

String url = "url you want to download"; 
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); 
request.setDescription("Some descrition"); 
request.setTitle("Some title"); 

回答

1

onItemClick中,您放置了在單擊項目時想要發生的操作。