【发布时间】:2014-02-20 05:53:28
【问题描述】:
我有一个列表视图,我在其中从服务器加载音频文件,并通过单击它播放的任何项目来播放该音频。现在我有一个问题是我得到的是绝对路径的完整路径,我只想要那个文件的名称。
所以基本上在上图中,您可以看到它正在打印带有 //..../.mp3 的完整路径,我只想显示文件名。那么我该怎么做。
我已经尝试了许多解决方案,例如 .getName() 方法与文件和字符串对象,但它不能正常工作。
下面是我的代码。
@Override
protected String doInBackground(String... arg0) {
try {
urlAudio = new URL("http://server/folder/uploadAudio");
} catch (MalformedURLException e) {
e.printStackTrace();
}
ApacheURLLister lister1 = new ApacheURLLister();
List<String> tempList = new ArrayList<String>();
try {
tempList = lister1.listAll(urlAudio);
} catch (IOException e) {
e.printStackTrace();
}
for (int i = 0; i < tempList.size(); i++) {
myList.add(tempList.get(i).split("/")[tempList.get(i)
.split("/").length - 1]);
}
return null;
}
任何帮助将不胜感激。提前谢谢你。
【问题讨论】:
-
使用 string.split() 方法
-
@user88,我必须在哪里使用这个 string.split?
-
可以上传
listAll()方法的代码吗? -
@Kedarnath,listAll() 是默认方法,无需明确定义,我使用了 apache ivy 库来处理它。
-
谁投反对票,请说明原因。
标签: android android-listview absolute-path