android - How to Show Popup Menu near to Listview each item on Item Click Event? -


how show popup menu near listview each item on item click event ?

this code. want show popup menu near listview item on item click. shows @ bottom only. me show popup menu near list item clicked. thank .

   package saro.example.com.task2_listview;      import android.app.dialog;     import android.content.context;     import android.content.dialoginterface;     import android.os.build;     import android.support.annotation.requiresapi;     import android.support.v7.app.alertdialog;     import android.support.v7.app.appcompatactivity;     import android.os.bundle;      import android.view.contextmenu;     import android.view.gravity;     import android.view.layoutinflater;     import android.view.menu;     import android.view.view;     import android.view.viewgroup;     import android.widget.adapterview;     import android.widget.arrayadapter;     import android.widget.listview;     import android.widget.listadapter;     import android.widget.popupwindow;     import android.widget.textview;     import android.content.context;     import android.widget.toast;     import android.widget.popupmenu;      public class mainactivity extends appcompatactivity {         listview list;         @override         protected void oncreate(final bundle savedinstancestate) {             string[] mobilearray = {"android", "iphone", "windowsmobile", "blackberry",                     "webos", "ubuntu", "windows7", "max os x","android", "iphone", "windowsmobile", "blackberry"};              super.oncreate(savedinstancestate);             setcontentview(r.layout.activity_main);              arrayadapter adapter = new arrayadapter<string>(this,                     r.layout.activity_listview, mobilearray);              list = (listview) findviewbyid(r.id.mobile_list);             list.setadapter(adapter);              list.setonitemclicklistener(new adapterview.onitemclicklistener() {                  public void onitemclick(adapterview<?> parent, view v, int position, long id) {                      int pos = parent.getpositionforview(v);                     toast.maketext(getapplicationcontext(),pos+"",toast.length_short).show();                      popupmenu popup = new popupmenu(mainactivity.this, list);                     popup.getmenuinflater().inflate(r.menu.popup_menu, popup.getmenu());     //                              popup.show();                  }              });         }     } 

thanks in advance.

try pass of adapter view v insted of list view in pop menu below code

use this popupmenu popup = new popupmenu(mainactivity.this, v);

insted of popupmenu popup = new popupmenu(mainactivity.this, list);

code

list.setonitemclicklistener(new adapterview.onitemclicklistener() {                  public void onitemclick(adapterview<?> parent, view v, int position, long id) {                      int pos = parent.getpositionforview(v);                     toast.maketext(getapplicationcontext(),pos+"",toast.length_short).show();                      popupmenu popup = new popupmenu(mainactivity.this, v);                     popup.getmenuinflater().inflate(r.menu.popup_menu, popup.getmenu());     //                              popup.show();                  }              }); 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -