Android bind custom dialog to item (like context menu) -
i've created custom dialog , want bind textview.
want dialog behave context menu when click on textview.
in other words, don't want dialog appear in center of screen, appear near textview.
certainly, can calculate needed position of dialog, me, it's not way. i've spent lot of time searching way, unfortunately no result. there solution?
thanks in advance help!
finally found there popupmenu in android, cover issue.
example of usage:
1. create menu in xml:
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/item_movies" android:showasaction="ifroom|withtext" android:title="movies" android:visible="true"/> <item android:id="@+id/item_music" android:showasaction="ifroom|withtext" android:title="music" android:visible="true"/> <item android:id="@+id/item_comedy" android:showasaction="ifroom|withtext" android:title="comedy" android:visible="true"/> </menu> 2. basic implementation of activity:
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); findviewbyid(r.id.btn_click).setonclicklistener(new onclicklistener() { @override public void onclick(view view) { popupmenu popupmenu = new popupmenu(popmenuactivity.this, view); popupmenu.setonmenuitemclicklistener(popmenuactivity.this); popupmenu.inflate(r.menu.popup_menu); popupmenu.show(); } }); } public boolean onmenuitemclick(menuitem item) { switch (item.getitemid()) { case r.id.item_comedy: toast.maketext(this, "comedy clicked", toast.length_short).show(); return true; case r.id.item_movies: toast.maketext(this, "movies clicked", toast.length_short).show(); return true; case r.id.item_music: toast.maketext(this, "music clicked", toast.length_short).show(); return true; } } that's looking for.

Comments
Post a Comment