title: incredibly slow app using array of images in a gridview
body: <p>I have the following little app that displays a grid of photos.  When a photo is pressed/clicked, then a larger version opens up.</p>
  
  <p>Technically, it works.  However, it's very slow in my Android virtual device.  I am also seeing these messages pop-up in the Android Studio logs.</p>
  
  <blockquote>
    <p>I/Choreographer: Skipped 38 frames!  The application may be doing too
    much work on its main thread.</p>
  </blockquote>
  
  <p>So I must be doing something wrong.</p>
  
  <p>Given the code below, is there a way to "fix" this?</p>
  
  <p>Thanks!</p>
  
  <pre><code>package com.zeus.miniapps.photoviewer;
  
  import android.content.Context;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AdapterView;
  import android.widget.BaseAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;
  import android.widget.Toast;
  
  
  public class ImageGrid extends AppCompatActivity {
  
      Integer[] ApocImages =  {R.drawable.image1, R.drawable.image2, R.drawable.image3, R.drawable.image4,
                               R.drawable.image5, R.drawable.image6, R.drawable.image7, R.drawable.image8,
                               R.drawable.image9, R.drawable.image10, R.drawable.image11, R.drawable.image12,
                               R.drawable.image13, R.drawable.image14, R.drawable.image15, R.drawable.image16};
  
      ImageView pic;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_image_grid);
          GridView grid = findViewById(R.id.gridView);
          final ImageView pic = findViewById(R.id.imgLarge);
          grid.setAdapter(new ImageAdapter(this));
          pic.setClickable(true);
  
          grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
                  Toast.makeText(getBaseContext( ), "Selected Image " + (position + 1), Toast.LENGTH_SHORT).show( );
                  pic.setVisibility(View.VISIBLE);
                  pic.setImageResource(ApocImages[position]);
              }
          });
  
          pic.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  pic.setVisibility(View.INVISIBLE);
              }
          });
      }
  
      public class ImageAdapter extends BaseAdapter {
          private Context context;
  
          public ImageAdapter(Context c) {
              context = c;
          }
  
          public int getCount() {
              return ApocImages.length;
          }
  
          public Object getItem(int position) {
              return null;
          }
  
          public long getItemId(int position) {
              return 0;
          }
  
          public View getView(int position, View contentView, ViewGroup parent) {
              pic = new ImageView(context);
              pic.setImageResource(ApocImages[position]);
              pic.setScaleType(ImageView.ScaleType.FIT_XY);
              pic.setLayoutParams(new GridView.LayoutParams(330, 300));
              return pic;
          }
  
      }
  }
  </code></pre>
  
  <p>Here's a screenshot of this awesome app in action!</p>
  
  <p><a href="https://i.stack.imgur.com/5WQ83.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5WQ83.png" alt="enter image description here"></a></p>