Question

Does anyone know any library, how to achieve this or any sorcery has been made for this.

a list view with context menu? I don't want to use the one with long click context menu.

Thanks

enter image description here enter image description here

Was it helpful?

Solution

Just Create menu.xml in res/menu folder Like below example

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_item1" android:title="@string/menu_item1"/ >
<item android:id="@+id/menu_item2" android:title="@string/menu_item2" >
<!-- "file" submenu -->
<menu>
    <item android:id="@+id/sub_menu_item1"
        android:title="@string/sub_menu_item1" />
    <item android:id="@+id/sub_menu_item2"
        android:title="@string/sub_menu_item2" />
</menu>

Create an image Button like bellow example in your layout

<ImageButton
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:src="@drawable/ic_overflow_holo_dark"
android:contentDescription="@string/descr_overflow_button"
android:onClick="showPopup" />

Create Method that display your popup-menu.

public void showPopup(View v) {
  PopupMenu popup = new PopupMenu(this, v);

  // action is your menu.xml file
  // This activity implements OnMenuItemClickListener
  popup.setOnMenuItemClickListener(this);
  popup.inflate(R.menu.actions);
  popup.show();
}
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
   // your menu id and perform action 
    case R.id.archive:
        archive(item);
        return true;
    case R.id.delete:
        delete(item);
        return true;
    default:
        return false;
}
}

and you can follow This tutorial

OTHER TIPS

It's called a PopupMenu and can be placed anywhere. The documentation is here: http://developer.android.com/reference/android/widget/PopupMenu.html

Normally you would have an ImageButton with an overflow image resource and set the on click listener to display the PopupMenu using the ImageButton as the anchor view.

here is sample of CARDLIB

enter image description here


enter image description here

Please take a look you 'll found solution

HERE IS CODE

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top