gpt4 book ai didi

java - 从 xml 文件下载文件

转载 作者:行者123 更新时间:2023-12-01 15:15:35 24 4
gpt4 key购买 nike

我将一个指向 mp3 音乐文件地址的 URL 插入到一个 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");

最佳答案

onItemClick 中,您可以输入单击该项目时希望发生的操作。

关于java - 从 xml 文件下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11654934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com