ImageView imageView = findViewById(R.id.my_image_view); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // Respond to the click event here } });
ImageView imageView = findViewById(R.id.my_image_view); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(MainActivity.this, LargeImageActivity.class); intent.putExtra("image_id", R.drawable.large_image); startActivity(intent); } });In this example, we create an Intent to launch a new activity called LargeImageActivity that will display a larger version of the image. We pass the ID of the image resource as an extra with the Intent, which we can use to load the image in the new activity. The package library for android.widget.ImageView is part of the Android SDK, specifically the android.widget package.