1

I am currently working on my final project in university and it looks like instagram. In instagram android app you could tap and hold on image and boom, shows a popup. But i can't figure out how to do this!

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • here check [this](https://stackoverflow.com/questions/4402740/android-long-click-on-a-button-perform-actions/4402854#4402854) out. – Jordan Jan 28 '18 at 12:54

1 Answers1

1

You can use below code to perform such types of action :

ImageView imageView = (ImageView ) findViewById(R.id.imageView2 );
imageView .isClickable();

imageView .setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Toast.makeText(getBaseContext(), "Clicked", Toast.LENGTH_SHORT).show();
        // Here we can use to full view of image.
    }
});

imageView .setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        // TODO Auto-generated method stub
        Toast.makeText(getBaseContext(), "Long Clicked", Toast.LENGTH_SHORT).show();
         // Here we can use to show dialog.
         showDialog();
        return true;
    }
});

Create your Popup/Dialog on same Activity :

 public void showDialog(){


  AlertDialog.Builder builder = new AlertDialog.Builder(this);  
        //Uncomment the below code to Set the message and title from the strings.xml file  
        //builder.setMessage(R.string.dialog_message) .setTitle(R.string.dialog_title);  

        //Setting message manually and performing action on button click  
        builder.setMessage("Do you want to Like")  
            .setCancelable(false)  
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {  
                public void onClick(DialogInterface dialog, int id) {  
                finish();  
                }  
            })  
            .setNegativeButton("No", new DialogInterface.OnClickListener() {  
                public void onClick(DialogInterface dialog, int id) {  
                //  Action for 'NO' Button  
                dialog.cancel();  
             }  
            });  

        //Creating dialog box  
        AlertDialog alert = builder.create();  
        //Setting the title manually  
        alert.setTitle("AlertDialogExample");  
        alert.show();  

}
Abhishek kumar
  • 4,347
  • 8
  • 29
  • 44