2012-03-26 43 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