Long Press Menu Implementation for Android App

TRUETECH is engaged in the development, support and maintenance of iOS, Android, PWA mobile applications. We have extensive experience and expertise in publishing mobile applications in popular markets like Google Play, App Store, Amazon, AppGallery and others.
Development and support of all types of mobile applications:
Information and entertainment mobile applications
News apps, games, reference guides, online catalogs, weather apps, fitness and health apps, travel apps, educational apps, social networks and messengers, quizzes, blogs and podcasts, forums, aggregators
E-commerce mobile applications
Online stores, B2B apps, marketplaces, online exchanges, cashback services, exchanges, dropshipping platforms, loyalty programs, food and goods delivery, payment systems.
Business process management mobile applications
CRM systems, ERP systems, project management, sales team tools, financial management, production management, logistics and delivery management, HR management, data monitoring systems
Electronic services mobile applications
Classified ads platforms, online schools, online cinemas, electronic service platforms, cashback platforms, video hosting, thematic portals, online booking and scheduling platforms, online trading platforms

These are just some of the types of mobile applications we work with, and each of them may have its own specific features and functionality, tailored to the specific needs and goals of the client.

Showing 1 of 1 servicesAll 1735 services
Long Press Menu Implementation for Android App
Simple
~1 business day
FAQ
Our competencies:
Development stages
Latest works
  • image_mobile-applications_feedme_467_0.webp
    Development of a mobile application for FEEDME
    756
  • image_mobile-applications_xoomer_471_0.webp
    Development of a mobile application for XOOMER
    624
  • image_mobile-applications_rhl_428_0.webp
    Development of a mobile application for RHL
    1052
  • image_mobile-applications_zippy_411_0.webp
    Development of a mobile application for ZIPPY
    947
  • image_mobile-applications_affhome_429_0.webp
    Development of a mobile application for Affhome
    862
  • image_mobile-applications_flavors_409_0.webp
    Development of a mobile application for the FLAVORS company
    445

Implementing Long Press Menu for Android Applications

Long press is a gesture users intuitively expect: holding down on a list item opens contextual actions. In practice, implementation breaks in two places: incorrect gesture recognition during fast RecyclerView scrolling and visually unclear menu display.

Implementation Options

PopupMenu — the simplest approach for lists with fixed actions. It attaches to a View via an anchor and inflates from an XML resource:

itemView.setOnLongClickListener { view ->
    val popup = PopupMenu(view.context, view)
    popup.menuInflater.inflate(R.menu.context_item_menu, popup.menu)
    popup.setOnMenuItemClickListener { menuItem ->
        when (menuItem.itemId) {
            R.id.action_delete -> { onDelete(item); true }
            R.id.action_share  -> { onShare(item); true }
            else -> false
        }
    }
    popup.show()
    true
}

Issue: PopupMenu appears at a corner of the View without positional animation. On small screens or in the lower part of a list, the menu goes off-screen. From API 28 onwards, setForceShowIcon(true) enables icons in PopupMenu—without this flag, icons from menu.xml are simply ignored.

ContextMenu via registerForContextMenu() — a deprecated approach, tied to Activity and works poorly with RecyclerView.

BottomSheetDialog — the preferred choice for modern Material Design 3 applications. Visually cleaner, independent of element position on screen, easily extensible. Implemented via MaterialAlertDialogBuilder or a custom BottomSheetDialogFragment.

Scrolling and Gesture Issues

In RecyclerView, OnLongClickListener competes with ItemTouchHelper if used for swiping. If ItemTouchHelper consumes the event first, onLongClick doesn't fire. Solution: explicitly handle MotionEvent.ACTION_DOWN and ACTION_CANCEL in OnItemTouchListener, delegating control after a timeout based on ViewConfiguration.getLongPressTimeout().

Another consideration: haptic feedback on long press. view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS) is called manually within onLongClick because the system doesn't guarantee it automatically for custom views.

Compose

In Jetpack Compose, use combinedClickable:

Box(
    modifier = Modifier.combinedClickable(
        onClick = { onClick(item) },
        onLongClick = { showMenu = true }
    )
) {
    // item content
    DropdownMenu(
        expanded = showMenu,
        onDismissRequest = { showMenu = false }
    ) {
        DropdownMenuItem(text = { Text("Delete") }, onClick = { onDelete(item); showMenu = false })
        DropdownMenuItem(text = { Text("Share") }, onClick = { onShare(item); showMenu = false })
    }
}

DropdownMenu positions itself automatically relative to the parent Box—the platform handles off-screen boundary issues.

Common Mistakes

Menu opens during scroll. Cause: OnLongClickListener on itemView without checking scroll state. Fix: verify recyclerView.scrollState == RecyclerView.SCROLL_STATE_IDLE before showing the menu.

No visual feedback while holding. The itemView should have android:background="?attr/selectableItemBackground" for correct ripple effect on long press.

Implementation complexity ranges from a few hours (simple PopupMenu) to 1–2 days (custom BottomSheet with animations and multi-select). Cost is calculated individually.