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.
// 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);
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"
/>