1
나는 사용자가 특정 파일을 클릭하면 SD 카드의 특정 폴더에 저장되어있는 오디오 파일의 동적 목록 listview가 내가 onItemClick 메서드에서 int에 postion을 얻을 것이다 내가 만들 필요가 두 개의 버튼이있는 경고 대화 상자는 특정 위치의 해당 특정 파일을 재생하는 것이며 두 번째는 해당 파일을 삭제하는 것입니다. 어떻게해야합니까?동적으로 안드로이드에서 오디오 파일을 재생하는 방법
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();
}
당신이 그 일을하지 않는 방법을 생각하는 데 도움이 코드 :
문자열 file_path_in_the_sd_card = YOURADAPTER.getFilePathAtPosition (position); 이 줄을 내게 오류가 발생했습니다 ... – Rahul
어댑터에이 방법을 구현해야합니다. 어쩌면 어댑터 코드를 게시하면 YOURADAPTER에서 – confucius
이 내 어댑터의 개체를 전달하지만 잘 작동하는 작업을 수행 할 수 있지만 오류가 발생합니다. – Rahul