@Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { // Adjust the item position to account for the parent folder row that is inserted // at the top of the list when viewing the contents of a folder. final BookmarksListAdapter adapter = getBookmarksListAdapter(); if (adapter.isShowingChildFolder()) { position--; } return super.onItemLongClick(parent, view, position, id); }
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final ListView list = (ListView) parent; final int headerCount = list.getHeaderViewsCount(); if (position < headerCount) { // The click is on a header, don't do anything. return; } // Absolute position for the adapter. position -= headerCount; final BookmarksListAdapter adapter = getBookmarksListAdapter(); if (adapter.isShowingChildFolder()) { if (position == 0) { // If we tap on an opened folder, move back to parent folder. adapter.moveToParentFolder(); return; } // Accounting for the folder view. position--; } final Cursor cursor = adapter.getCursor(); if (cursor == null) { return; } cursor.moveToPosition(position); int type = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks.TYPE)); if (type == Bookmarks.TYPE_FOLDER) { // If we're clicking on a folder, update adapter to move to that folder final int folderId = cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks._ID)); final String folderTitle = adapter.getFolderTitle(parent.getContext(), cursor); adapter.moveToChildFolder(folderId, folderTitle); } else { // Otherwise, just open the URL final String url = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.URL)); // This item is a TwoLinePageRow, so we allow switch-to-tab. getOnUrlOpenListener() .onUrlOpen(url, EnumSet.of(OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB)); } }