2012-03-26 73 views
1

動態播放一段音頻文件,我有與存儲在一個特定的文件夾在SD卡中的音頻文件的動態列表,列表視圖,當用戶點擊一個特定的文件,我會得到現在的位置是在int類型onItemClick方法我需要創建首先有兩個按鈕的提醒對話框是播放該特定位置的特定文件,其次是刪除該文件。這個怎麼做?如何在Android的

回答

0

onItemClickListener註冊列表和方法內填充對話框,有2個按鈕

這裏是一些代碼:

mylistview.setOnItemClickListener(new OnItemClickListener() { 

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

      String file_path_in_the_sd_card = YOURADAPTER.getFilePathAtPosition(position); 

      AlertDialog.Builder builder = new AlertDialog.Builder(this); 
      builder.setMessage("Option") 
        .setCancelable(false) 
        .setPositiveButton("Play", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          //start the activity the will play the song and provide the path to it 

         } 
        }) 
        .setNegativeButton("Delete", new DialogInterface.OnClickListener() { 
         public void onClick(DialogInterface dialog, int id) { 
          //make a code that will delete the file maybe like this 
          File file = new File(file_path_in_sd_card); 
          file.delete(); 

          //remove it aslo from your adapter 

          myadpter.removeFile(poistion); 
          myadpater.notifyDataSetChange(); 

          dialog.cancel(); 
         } 
        }); 
      AlertDialog alert = builder.create(); 




} 

這個代碼,以幫助您認爲該怎麼做工作也沒有一個完整的例子。

+0

字符串file_path_in_the_sd_card = YOURADAPTER.getFilePathAtPosition(位置);此行給我的錯誤.. – Rahul 2012-03-26 08:14:32

+0

,你應該在你的適配器實現此方法,也許如果發表您的適配器的代碼,我會做一些工作正常你認爲 – confucius 2012-03-26 08:15:38

+0

在YOURADAPTER IM通過我的適配器的對象,但它給我錯誤 – Rahul 2012-03-26 08:19:10