I have a custom list-view with check-boxes which get's all audio file name from SD Card folder and when i click any of this it play's audio. Everything is working fine. Now i have a image-view when i click on it, it show's 2 option with spinner
1) Delete
2) Edit
Now i want like this, when user select any check-box from list-view and then delete from this spinner, i want to completely remove this audio from SD Card as well as from List-view. So basically i want to get position of list-view that which item is clicked by user and want to delete it...
So please guide me how can i achieve this. Below is my code.
final Spinner spinnerDelete = new Spinner(Assignment.this);
alertDialogBuilder.setView(spinnerDelete);
adapterSpinner = ArrayAdapter.createFromResource(
Assignment.this, R.array.delete_menu,
android.R.layout.simple_spinner_item);
adapterSpinner
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerDelete.setAdapter(adapterSpinner);
alertDialogBuilder.setTitle("Delete Data");
alertDialogBuilder
.setMessage("Click yes to Delete Record!")
.setCancelable(false)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
if (spinnerDelete
.getSelectedItemPosition() == 0) {
Code.i = true;
int len = mListView.getCount();
SparseBooleanArray checked = mListView
.getCheckedItemPositions();
for (int i = 0; i < len; i++)
if (checked.get(i)) {
File file = new File(MEDIAPATH);
boolean deleted = file.delete(); }
where media path contains
private static final String MEDIA_PATH = new String(
Environment.getExternalStorageDirectory() + "/AudioRecorder/");
I have tried with below link but not getting solution as i want
How to delete a file from SD card?
Delete File in SD Card android with string
Delete file on sd card from a listview
Delete file on sd card from a listview
How can I make a file to disappear once if it is deleted in android SD card?