我正在尝试让文件管理器从 sdcard 中删除文件。只有一个路径“/sdcard/Soundcast/”,我希望能够从中删除 .mp4 和 .3gp 文件。这是我的代码:
公共类 MainActivity 扩展 ListActivity {
private List<String> items =null;
private void deleteFile()
{
// TODO: Implement this method
}
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
getFiles(new File("/sdcard/Soundcast").listFiles()); }
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{ int selectedRow = (int)id; if (selectedRow == 0)
{ getFiles(new File("/sdcard/Soundcast").listFiles()); }
else
{ File file = new File(items.get(selectedRow)); if (file.isDirectory())
{ getFiles(file.listFiles()); }
else
{
new AlertDialog.Builder(this) .setTitle("Ability to open files will come in future updates.")
.setMessage("Do You Want To Delete this recording?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int button){
deleteFile();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int button){
}
}).show();}
}
}
private void getFiles(File[] files)
{ items = new ArrayList<String>();
items.add(getString(R.string.goto_root)); for (File file : files)
{ items.add(file.getPath()); }
ArrayAdapter<String> fileList = new ArrayAdapter<String>(this, R.layout.file_list_row, items);
setListAdapter(fileList); } }