mp3_info_item.xml: 用于显示相应的信息
java代码:
复制代码
(2) 、资源文件: values\strings.xml
java代码:
复制代码
(3)、主要逻辑代码:
1、用于下载本地文件的代码:
java代码:
复制代码
java代码:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- xmlns:android=http://schemas.android.com/apk/res/android
- android:orientation="horizontal"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:paddingLeft="10px"
- android:paddingRight="10px"
- android:paddingTop="1px"
- android:paddingBottom="1px"
- >
- <TextView
- android:id="@+id/mp3_name"
- android:layout_width="180dip"
- android:layout_height="wrap_content"
- android:textSize="10pt"/>
- <TextView
- android:id="@+id/mp3_size"
- android:layout_width="180dip"
- android:layout_height="wrap_content"
- android:textSize="10pt"
- />
- </LinearLayout>
(2) 、资源文件: values\strings.xml
java代码:
- <?xml version="1.0" encoding="utf-8"?>
- <resources>
- <string name="hello">Hello World, Mp3ListActivity!</string>
- <string name="app_name">mp3player</string>
- <string name="mp3list_update">更新列表</string>
- <string name="mp3list_about">关于</string>
- </resources>
(3)、主要逻辑代码:
1、用于下载本地文件的代码:
java代码:
- package eoe.demo;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.InputStreamReader;
- import java.net.HttpURLConnection;
- import java.net.URL;
- public class HttpDownloader {
- private URL url=null;
- public String download(String urlStr){
- StringBuffer sb=new StringBuffer();
- String line=null;
- BufferedReader buffer=null;
- try{
- url=new URL(urlStr);
- HttpURLConnection urlConn=(HttpURLConnection)url.openConnection();
- buffer=new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
- while((line=buffer.readLine())!=null){
- sb.append(line);
- }
- }catch(Exception e){
- e.printStackTrace();
- }finally{
- try{
- buffer.close();
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- return sb.toString();
- }
- /*
- * 该函数返回整形:-1 表示下载文件出错 0 表示下载文件成功 1 表示下载文件已经存在
- */
- /* public int downFile(String urlStr,String path,String fileName){
- InputStream inputStream=null;
- try{
- FileUtils fileUtils=new FileUtils();
- if(fileUtils.isFileExist(path+fileName)){
- return 1;
- }else{
- inputStream=getInputStreamFromUrl(urlStr);
- File resultFile=fileUtils.write2SDFromInput(path, fileName, inputStream);
- if(resultFile==null){
- return -1;
- }
- }
- }catch(Exception e){
- e.printStackTrace();
- return -1;
- }finally{
- try {
- inputStream.close();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- return 0;
- }
- public InputStream getInputStreamFromUrl(String urlStr) throws IOException{
- url=new URL(urlStr);
- HttpURLConnection urlConn=(HttpURLConnection)url.openConnection();
- InputStream inputStream=urlConn.getInputStream();
- return inputStream;
- }*/
- }