1

I want to a pop up like this is facebook

enter image description here

Hello Guys, Above is the image where you can see a popup comes over a button. I tried achieving this using AleartDialog but it opens in center. I want it below that button only.

LayoutInflater inflater = (LayoutInflater) 
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.layout_show_options, null);
 new AlertDialog.Builder(this)
            .setView(view)
            .create().show();

Any help would be appreciated. Thanks

Rohit5k2
  • 17,948
  • 8
  • 45
  • 57
kvaruna
  • 388
  • 1
  • 4
  • 23
  • please refer this link https://stackoverflow.com/questions/46440245/show-popup-in-recyclerview-exactly-where-the-button-is-in-android – Mohsin mithawala Jun 01 '18 at 09:59
  • Possible duplicate of [How to display a custom Dialog box at a specific position?](https://stackoverflow.com/questions/22350327/how-to-display-a-custom-dialog-box-at-a-specific-position) – Anuraag Baishya Jun 01 '18 at 10:02
  • Check out this tutorial -> https://guides.codepath.com/android/menus-and-popups – Sebastian M Jun 01 '18 at 10:02
  • Hello All, Great going with the given source and examples. Now just having some issues like the popup goes beyond the screen and becomes invisible to user. Trying to sort it out rest is good. – kvaruna Jun 01 '18 at 10:50

2 Answers2

0

Use Pop Up menu open menu on your button click menu.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/mail"
        android:icon="@drawable/ic_mail"
        android:title="@string/mail" />
    <item android:id="@+id/upload"
        android:icon="@drawable/ic_upload"
        android:title="@string/upload"
        android:showAsAction="ifRoom" />
    <item android:id="@+id/share"
        android:icon="@drawable/ic_share"
        android:title="@string/share" />
</menu>

Java Code:

 public void showMenu(View v) {
        PopupMenu popup = new PopupMenu(this, v);
        popup.setOnMenuItemClickListener(this);
        popup.inflate(R.menu.actions);
        popup.show();
    }

@Override
public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.archive:
            archive(item);
            return true;
        case R.id.delete:
            delete(item);
            return true;
        default:
            return false;
    }
}
Milan Pansuriya
  • 2,521
  • 1
  • 19
  • 33
0

Use Popup menu

    <?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/unfriend"
        android:icon="@drawable/ic_mail"
        android:title="Unfriend" />
    <item android:id="@+id/edit_friend_list"
        android:icon="@drawable/ic_upload"
        android:title="Edit FriendList"
        android:showAsAction="ifRoom" />

</menu>


public void showPopup(View v) {
PopupMenu popup = new PopupMenu(this, v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.menu_example, popup.getMenu());
popup.show();

}

@Override
public boolean onMenuItemClick(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.unfriend:
            // 
            return true;
        case R.id.edit_friend_list:

            return true;
        default:
            return false;
    }
}

Hope it will help.

for more detail please visit below link.

https://www.tutlane.com/tutorial/android/android-popup-menu-with-examples

https://www.javatpoint.com/android-popup-menu-example

http://www.coderzheaven.com/2013/04/07/create-simple-popup-menu-android/

Yogendra
  • 4,817
  • 1
  • 28
  • 21
  • Hi, With help of your example and the links i made the popup appear on screen as it is on recyclerview item, sometimes depending on the position of that button it goes beyond the screen and becomes invisible. Any idea where should I dig ? @yogendra – kvaruna Jun 01 '18 at 11:31