Can anyone please help me here? Thanks.
On Feb 4, 4:15 pm, newbie <[email protected]> wrote: > Hi, > > I am trying to write an app which has an ImageView and the app allows > to perform panning on the image. I also want to register context menu > with this ImageView so that on long press Context menu comes up. I > tried playing around with the onTouch method, but could not get it > working. > > On long press, i do see context menu. But, while panning also the > context menu comes up. I want that context menu is displayed only when > long press is performed and not while panning. If I return true from > the down event, the context menu fails to come up. > > Please find the snippet of the code below for the reference. > > public void onCreate(Bundle savedInstanceState) { > super.onCreate(savedInstanceState); > setContentView(R.layout.main); > > ImageView image = (ImageView) findViewById(R.id.image_id); > image.setOnTouchListener(this); > registerForContextMenu(image); > } > > public boolean onTouch(View view, MotionEvent event) > { > switch (event.getAction()) { > case MotionEvent.ACTION_DOWN: > mXPos = event.getRawX(); > mYPos = event.getRawY(); > return false; > case MotionEvent.ACTION_MOVE: > float newXPos = event.getRawX(); > float newYPos = event.getRawY(); > > view.scrollBy((int)(mXPos - newXPos), (int)(mYPos - > newYPos)); > mXPos = newXPos; > mYPos = newYPos; > return true; > case MotionEvent.ACTION_UP: > return false; > > } > return false; > } > > public void onCreateContextMenu(ContextMenu menu, View v, > ContextMenuInfo menuInfo) { > menu.add(Menu.NONE, 0, Menu.NONE, "Item1"); > menu.add(Menu.NONE, 1, Menu.NONE, "Item2"); > } > > private float mXPos, mYPos; > > Thanks in Advance. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

