Advertisement
Guest User

DetailActivity

a guest
Jul 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. package com.example.catalogmovie;
  2.  
  3. import android.media.Image;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.view.MenuItem;
  7. import android.widget.ImageView;
  8. import android.widget.TextView;
  9.  
  10. import com.example.catalogmovie.Model.Movie;
  11.  
  12. public class DetailActivity extends AppCompatActivity {
  13.  
  14. public static final String KEY_EXTRA = "key_extra";
  15.  
  16. ImageView imgPhoto;
  17. TextView tvName;
  18. TextView tvYear;
  19. TextView tvRating;
  20. TextView tvGenre;
  21. TextView tvDescription;
  22.  
  23.  
  24. @Override
  25. protected void onCreate(Bundle savedInstanceState) {
  26. super.onCreate(savedInstanceState);
  27. setContentView(R.layout.activity_detail);
  28.  
  29. if (getSupportActionBar() != null) {
  30. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  31. }
  32.  
  33. imgPhoto = findViewById(R.id.img_photo);
  34. tvName = findViewById(R.id.tv_movie_name);
  35. tvYear = findViewById(R.id.tv_movie_year);
  36. tvRating = findViewById(R.id.tv_movie_rating);
  37. tvGenre = findViewById(R.id.tv_movie_genre);
  38. tvDescription = findViewById(R.id.tv_movie_description);
  39.  
  40. Movie movie = getIntent().getParcelableExtra(KEY_EXTRA);
  41. getSupportActionBar().setTitle(movie.getName());
  42.  
  43. String name = movie.getName();
  44. tvName.setText(name);
  45.  
  46. String year = movie.getYear();
  47. tvYear.setText(year);
  48.  
  49. String rating = movie.getRating();
  50. tvRating.setText(rating);
  51.  
  52. String genre = movie.getGenre();
  53. tvGenre.setText(genre);
  54.  
  55. String description = movie.getDescription();
  56. tvDescription.setText(description);
  57.  
  58. // int photo = movie.getPhoto();
  59. // imgPhoto.setImageResource(photo);
  60. // String photo = movie.getPhoto();
  61. // imgPhoto.setImageBitmap(photo);
  62.  
  63. int photo = movie.getPhoto();
  64. imgPhoto.setImageResource(photo);
  65. }
  66.  
  67. @Override
  68. public boolean onOptionsItemSelected(MenuItem item) {
  69.  
  70. switch (item.getItemId()) {
  71. case android.R.id.home:
  72. onBackPressed();
  73. }
  74.  
  75. return super.onOptionsItemSelected(item);
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement