@Override public boolean onContextItemSelected(MenuItem item) { if (item.getItemId() == R.id.mnuDelete) { // they have requested that we delete the selected race AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); ListView list = (ListView) info.targetView.getParent(); DBPathEntry db = (DBPathEntry) list.getItemAtPosition(info.position); try { if (db.GetFile().delete()) { Toast.makeText(this, "Database deleted", Toast.LENGTH_LONG).show(); } else { Toast.makeText(this, "Failed to delete DB", Toast.LENGTH_LONG).show(); } } catch (Exception e) { Toast.makeText(this, "Failed to delete file " + e.toString(), Toast.LENGTH_LONG).show(); } FirstTimeSetup(); // refresh the list return true; } else if (item.getItemId() == R.id.mnuRename) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); ListView list = (ListView) info.targetView.getParent(); DBPathEntry db = (DBPathEntry) list.getItemAtPosition(info.position); // they have requested that we rename the selected race Dialog d = new RenameDialog<DBPathEntry>(this, "Set the new DB name", db, R.id.edtRename); d.setOnDismissListener(this); d.show(); return true; } return false; }
@Override public void onItemClick(AdapterView<?> list, View view, int position, long id) { if (list.getId() == android.R.id.list) { synchronized (RaceDatabase.class) { // they've selected something from our list DBPathEntry db = (DBPathEntry) list.getItemAtPosition(position); // the filename they want is GetParentPath + cs + ".wflp" String strFilename = MakeParentPath() + db.toString() + ".wflp"; File fPicked = new File(strFilename); if (fPicked.exists()) { AlertDialog ad = new AlertDialog.Builder(this).create(); ad.setMessage( "You are about to overwrite all your recorded race sessions. Data will be lost. Make sure to back them up using the save button (right side) first."); ad.setButton(AlertDialog.BUTTON_POSITIVE, "Ok", this); ad.setButton(AlertDialog.BUTTON_NEGATIVE, "Cancel", this); m_copyThis = fPicked; m_dbWarning = ad; ad.show(); } else { Toast.makeText(this, "Could not find file " + strFilename, Toast.LENGTH_LONG).show(); } } } }