0

I have a little problem: I would like to exit the content view that I can started when I click on an image of the layout. The code is:

final View thumb1View = findViewById(R.id.gorgovivofoto1);
    thumb1View.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            TouchImageView img = new TouchImageView(view.getContext());
            img.setImageResource(R.drawable.gorgovivofoto1);
            img.setMaxZoom(4f);
            setContentView(img);

        }
    });

This code open a new content view where I can zoom my image, but I want to return back on double click on the image. Is it possible?

1 Answers1

0

There are some different solutions here

Android: How to detect double-tap?,

here

How can i place double click event on ImageView in Android

and here

How can i place double click event on ImageView in Android.

To handle the back button:

You can handle this using: for API level 5

@Override
public void onBackPressed() {
    // your code.
}

and for older then API 5 use this:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // your code
        return true;
    }

    return super.onKeyDown(keyCode, event);
}
Seraphim's
  • 12,559
  • 20
  • 88
  • 129
  • Thank you for your response. If I press back button the app exits from the activity instead of remain in. I set a setContentView and when I double click on on the setImageResource I want to return to the previous activity. I partially resolved adding this code after setContentView(img): `img.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startActivity(new Intent(acquaGorgovivoActivity.this, acquaGorgovivoActivity.class)); } });` – Francesco Esposto Feb 17 '16 at 09:16
  • But with this code I only can return to the previous activity clicking in the background but not on the image. – Francesco Esposto Feb 17 '16 at 09:19
  • If you want to handle the back button, I update my answer. – Seraphim's Feb 17 '16 at 09:24
  • Ok, you solved a part of the problem. But now I would like to return back if the contentView(img) is open. How can I resolve this? – Francesco Esposto Feb 17 '16 at 11:02
  • What "return back" means exactly? – Seraphim's Feb 17 '16 at 11:05
  • In acquaGorgovivoActivity there are some images, when I click on one of them the code opens a new contentView. If I want to exit from this content view I have to press "back button", but for now when I press back button it returns in Home activity. I would like to know if there is a possibility to execute your code only if `setContentView(img)` is executed. – Francesco Esposto Feb 17 '16 at 14:48
  • I would not substitute the content view of your thumbs viewer. I would use an overlay container where display the image and set its visibility to VISIBLE or GONE. – Seraphim's Feb 17 '16 at 14:52