@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); // Get the info on which item was selected AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; // Get the Adapter behind your ListView (this assumes you're using // a ListActivity; if you're not, you'll have to store the Adapter yourself // in some way that can be accessed here.) Adapter adapter = getListAdapter(); // Retrieve the item that was clicked on Object selItem = adapter.getItem(info.position); long mRowId = info.id; String itemStr = (String) selItem; menu.setHeaderTitle((String) selItem); menu.add(0, mDelete, 0, R.string.menu_delete); menu.add(0, mRename, 0, R.string.menu_rename); }
@Override public boolean onContextItemSelected(MenuItem item) { AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); File file; Adapter adapter = getListAdapter(); Object selItem = adapter.getItem(info.position); long mRowId = info.id; String itemStr = (String) selItem; // fileRegExp=".*"; switch (item.getItemId()) { case mDelete: this.deleteDatabase(itemStr); SharedPreferences mASHSettings = getSharedPreferences(ItemsOverview.ASH_PREFERENCES, Context.MODE_PRIVATE); SharedPreferences.Editor editor = mASHSettings.edit(); editor.putString(ItemsOverview.ASH_PREFERENCES_DBNAME, ""); editor.commit(); getDir(root, fileRegExp); // http://stackoverflow.com/questions/4406067/how-to-delete-sqlite-database-from-android-programmatically return true; case mRename: file = new File(root + itemStr); File newFile = new File(root + new StringBuilder().append(itemStr).append(".abb").toString()); file.renameTo(newFile); getDir(root, fileRegExp); // http://stackoverflow.com/questions/4406067/how-to-delete-sqlite-database-from-android-programmatically return true; } return super.onContextItemSelected(item); }