2012-04-04 11 views

答えて

0

ここは、Androidファイルエクスプローラに基づいた非常に良い例です。あなたのsdcardにあるすべてのファイルを表示します。

チェックこれだけmp3ファイルを表示したい場合は、http://android-er.blogspot.in/2010/01/implement-simple-file-explorer-in.html

は今、あなたは、単にファイル名で条件チェックをしなければなりません。

GETDIR(文字列dirPathの)このように、この例の方法、

private void getDir(String dirPath) 
{  
    myPath.setText("Location: " + dirPath); 
    item = new ArrayList<String>(); 
    path = new ArrayList<String>();   

    File f = new File(dirPath); 
    File[] files = f.listFiles(); 

    if(!dirPath.equals(root)) 
    {  
      item.add(root); 
      path.add(root);  
      item.add("../");  
      path.add(f.getParent()); 
    } 
    for(int i=0; i < files.length; i++)  
    { 
      File file = files[i]; 
      path.add(file.getPath()); 
      if(file.isDirectory())  
      item.add(file.getName() + "/"); 
      else 
      { 
       String filename=file.getName(); 
       String ext = filename.substring(filename.lastIndexOf('.')+1, filename.length()); 
       if(ext.equals("JPG")||ext.equals("jpg")) 
       { 
        item.add(file.getName()); 
       } 
      }  
    }  
    ArrayAdapter<String> fileList = 
      new ArrayAdapter<String>(this, R.layout.row, item); 
    setListAdapter(fileList); 
} 

今、あなたのエクスプローラが唯一のmp3ファイルを表示した準備ができているを交換してください。

+1

次のコードは、エラーを与えている:他 \t {\tストリングEXT = filename.substring( '' filename.lastIndexOf()+ 1、filename.length())。 \t if(ext.equals( "JPG")|| ext.equals( "jpg")) \t { \t item.add(file.getName()); \t} \t} mp3形式とは何ですか? –

+1

と申しますが、jpgの代わりにmp3に変更してください。あなたが得ているエラーは何ですか? –

+0

ファイル名に誤りがあります –

関連する問題