ListView listView = findViewById(R.id.list_view); listView.setOnCreateContextMenuListener(new ListView.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { // Add context menu items here menu.add("Delete"); menu.add("Edit"); } });In this example, we create a new instance of the ListView class and register a new OnCreateContextMenuListener using the setOnCreateContextMenuListener method. The listener is used to create a context menu with two options, "Delete" and "Edit", when a user long presses on an item in the list. This method is part of the android.widget package/library in Android.