Created
December 7, 2016 04:07
-
-
Save biodunalfet/0e8a934fa5d661e0c289f16be2e673e1 to your computer and use it in GitHub Desktop.
I got the ArtModel object sent from the previous activity and displayed it basically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.sep.loveartlearnart; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.v7.app.AppCompatActivity; | |
import android.widget.ImageView; | |
import android.widget.Toast; | |
import org.parceler.Parcels; | |
/** | |
* Created by Eni on 2016-12-05. | |
*/ | |
public class FullScreenImage extends AppCompatActivity { | |
private ImageView fullimageview; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.selected_image); | |
this.fullimageview = (ImageView) findViewById(R.id.full_image_view); | |
// Initialize the selected art as null | |
ArtModel model = null; | |
// Here I tried to get the selected ArtModel object by unwrapping the parcelable sent from the | |
// previous activity | |
// I added an exception handler here because you never know, anything could go wrong | |
// So if it's going to fail, it better do gracefully | |
try { | |
Intent intent = getIntent(); | |
model = Parcels.unwrap(intent.getParcelableExtra("selected_art")); | |
}catch (Exception e){ | |
e.printStackTrace(); | |
} | |
if (model != null){ | |
displayArt(model); | |
} | |
else { | |
Toast.makeText(this, "An error occurred. Try again", Toast.LENGTH_SHORT).show(); | |
} | |
} | |
/** | |
* | |
* @param model Art model to be displayed | |
* I'm just going to display the image | |
* You can do other things with the other properties of the model object | |
*/ | |
public void displayArt(ArtModel model){ | |
fullimageview.setImageResource(model.getImageResourceId()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment