Warning: Use of undefined constant _FILE_ - assumed '_FILE_' (this will throw an Error in a future version of PHP) in /home/bolyarco/www-ikratko/ogrelab/wp-content/plugins/ad-blocker-stats-vip/ad-blocker-stats-vip.php on line 13

Archive for July, 2011

Identifying the view selected in a ContextMenu (in onContextItemSelected() method)


Have you ever needed to popup a ContextMenu by longclicking on some of the UI element (different than item in ListView) for example an ImageView instance? At first glance it seems that this can be acomplished quite easy but in reality there is one big problem: you have only one onContextItemSelected() method in your activity that is called every time a context menu item is selected no matter which View requested the ContextMenu via openContextMenu(). This situation is not a problem if just one View is poping a ContextMenu but sometimes you need to popup ContextMenu from several different views. Let me show an example from a real app:

In this layout I have 4 ImageViews. img1 is called "primary" and all other "secondary". By specification I had to (more…)