我有listview的动态音频文件列表存储在sd卡的特定文件夹中,当用户点击一个特定的文件我将在onItemClick方法的int中获取位置我需要创建警告对话框,首先是两个按钮播放该特定位置的特定文件,其次是删除该文件。怎么做?
答案 0 :(得分: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();
}
这段代码可以帮助您思考如何完成这项工作,而不是一个完整的例子。