0

I placed some circle images in my layout and I would like to display content when the user hover on them or touch an image. I tried to search on google, but I found nothing useful about this topic.

I would like to display (i.e. on test1 image) a small window (like a pop-up window) with some text and one or two buttons when the user is hovering on the images.

Is it possible to do this in Android?

EDIT: This is the result I would like to achieve. For example, in this case, when the user hover or touch the image, a popup appears and show addition options.

enter image description here

        // Draw circles
    canvas.drawCircle((canvas.getWidth()/2)-300, canvas.getHeight()/2,60,paint);
    canvas.drawCircle((canvas.getWidth()/2), (canvas.getHeight()/2)-300,60,paint);
    canvas.drawCircle((canvas.getWidth()/2)+300, (canvas.getHeight()/2),60,paint);

    // load bitmap..
    Bitmap test = BitmapFactory.decodeResource(this.getResources(), R.drawable.img1);
    Bitmap test1 = MLRoundedImageView.getCroppedBitmap(test, 160);
    canvas.drawBitmap(test1, 468, 525, paint);
Marcus Barnet
  • 2,083
  • 6
  • 28
  • 36
  • 1
    What does "hover" mean in a touchscreen environment? Are you referring to users with some sort of active stylus? Or, are you referring to when the user is using a mouse? For those, you can [try `setOnHoverListener()`](https://developer.android.com/reference/android/view/View.html#setOnHoverListener(android.view.View.OnHoverListener)) to find out when the user is hovering over your whole view, but then you will need to determine if the user is hovering over a specific image. – CommonsWare Dec 27 '16 at 00:14
  • I edited my first topic in order to clearify what I would like to acquire. I would like to display additional content both on hover and on touch. It depends on the devices.. – Marcus Barnet Dec 27 '16 at 00:20

1 Answers1

1

This is not the exact solution but i think popupmenu works for this

PopupMenu popup = new PopupMenu(context, view_anchor);
popup.inflate(R.menu.your_menu);
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem item) {
                            switch (item.getItemId()) {
                                case R.id.button1:
                                    //code when button1 is clicked
                                    popup.dismiss();
                                    break;
                                case R.id.button2:
                                    //code when button2 is clicked
                                    popup.dismiss();
                                    break;
                            }
                            return false;
                        }
                    });
popup.show();

put the above code inside your image onclicklistener

to put onclicklistener in your image put this

ImageView image1, image2;

in oncreate
image1 = (ImageView) findViewById(R.id.id_of_image1);
image1.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //popup code
                        }
                    });

then in the xml put an id to your imageview

<ImageView
android:id="@+id/id_of_image1"
/>
Gilbert Mendoza
  • 405
  • 1
  • 7
  • 16
  • Thank you, Gilbert, for your help. Since I'm pretty new to android, I will need to figure out how to add a "onclicklistener" on my bitmaps and then I will try your suggestion.. thank you!! – Marcus Barnet Dec 27 '16 at 00:45
  • Thank you a lot for your help! I had to study few tutorials about menus and ImageView, but now I can finally run your code without errors.. thank you again!!! Now the manu is working fine! – Marcus Barnet Dec 27 '16 at 23:12