There are pictures that I add to the list from the gallery.

I want to click on them, they open in full screen.

How is it possible to do it right?

viewHolder.photo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { } }); } } 
  • You look at the photos from the gallery - that is, is there anything on the device? - Artem Shevchenko
  • @ArtemShevchenko exactly) - Inkognito

2 answers 2

For example:

Create ImageActivity :

 public class ImageActivity extends AppCompatActivity { private ImageView mImageView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image); mImageView = (ImageView) findViewById(R.id.my_image_view); Bundle extras = getIntent().getExtras(); if (extras != null) { int imageId = extras.getInt("image_id"); mImageView.setImageResource(imageId); } } } 

Her layout activity_image.xml :

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <ImageView android:id="@+id/my_image_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="fitCenter"/> </RelativeLayout> 

If you need to display a picture, launch ImageActivity :

 Intent intent = new Intent(getApplicationContext(), ImageActivity.class); intent.putExtra("image_id", R.drawable.my_image); startActivity(intent); 
  • super, only again, if I have a lot of pictures, then in mImageView.setImageResource and intent.putExtra we have to set the path to the getter in the model? - Inkognito
  • @Inkognito, Like that, but only when creating an intent. - post_zeew

Just pass it through Intent to Activity (in which you’ll show this photo) Uri , and then get Bitmap images:

 Uri imageUri = (Uri) getIntent().getParcelableExtra("IMAGE_URI"); // IMAGE_URI - ключт InputStream imageStream = getContentResolver().openInputStream(imageUri); Bitmap imageBitmap = BitmapFactory.decodeStream(imageStream); imageView.setImageBitmap(imageBitmap);