There can be a good solution than what I am going to offer but as even I'm learning and if it's just about 4 cardviews, I would've done the following.
Create a public static variable in MainActivity
public static Drawable resId;
set onClickListener for every Imageview
like this.
ImageView image1 = (ImageView) findViewById(R.id.image1);
image1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
resId = R.drawable.image1;
Intent intent = new Intent(MainActivity.this,your_fullscreen_activity_name.class);
startActivity(intent);
}
});
ImageView image2 = (ImageView) findViewById(R.id.image2);
image2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
resId = R.drawable.image2;
Intent intent = new Intent(MainActivity.this,your_fullscreen_activity_name.class);
startActivity(intent);
}
});
ImageView image3 = (ImageView) findViewById(R.id.image3);
image3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
resId = R.drawable.image3;
Intent intent = new Intent(MainActivity.this,your_fullscreen_activity_name.class);
startActivity(intent);
}
});
ImageView image4 = (ImageView) findViewById(R.id.image4);
image4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
resId = R.drawable.image4;
Intent intent = new Intent(MainActivity.this,your_fullscreen_activity_name.class);
startActivity(intent);
}
});
or on the cardviews, see here or here.
Create a fullscreenactivity and put its name in those intents.
Then in the java file of this fullscreenactivity, get the reference of layout/imageview and do this.
ViewGroup viewGroup = findViewById(R.id.fullscreenLayout);
viewGroup.setBackgroundDrawable(MainActivity.resId);
OR
ImageView imageView = findViewById(R.id.fullscreenImageview);
imageView .setBackgroundDrawable(MainActivity.resId);
You can use either the imageView
or the viewGroup
.
And yes, Don't forget to add id of layout in XML file of fullscreenactivity or create a imagview with size same as parent layout.
If anything is confusing/not helpful, I'll help.