Show popup in recyclerView exactly where the button is, in android

后端 未结 2 926
情书的邮戳
情书的邮戳 2021-01-25 12:44

I\'m working on a gridLayout with recyclerView in android.I\'ve a an option with each grid Item where I want to show my popup activity which is another class. Please see the im

2条回答
  •  春和景丽
    2021-01-25 13:18

    as per my above comment you can use Popup Menu

    Android Popup Menu displays the menu below the anchor text if space is available otherwise above the anchor text. It disappears if you click outside the popup menu.

    try this create menu file

    file: poupup_menu.xml

      
    
          
    
          
    
          
    
      
    

    than use create popup menu like this

    holder.img_chatroom_menu.setOnClickListener(new OnClickListener() {  
    
               @Override  
               public void onClick(View v) {  
                //Creating the instance of PopupMenu  
                PopupMenu popup = new PopupMenu(MainActivity.this, button1);  
                //Inflating the Popup using xml file  
                popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());  
    
                //registering popup with OnMenuItemClickListener  
                popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {  
                 public boolean onMenuItemClick(MenuItem item) {  
                  Toast.makeText(MainActivity.this,"You Clicked : " + item.getTitle(),Toast.LENGTH_SHORT).show();  
                  return true;  
                 }  
                });  
    
                popup.show();//showing popup menu  
               }  
              });//closing the setOnClickListener method  
    

    here is the sample demo links how to create pop-up menu in android

提交回复
热议问题