title: Android full image with recyclerview, cardview and volley from php mysql
body: <p>The code below downloads images from a server and displays them in a recyclerview using php mysql and volley library as seen in the image. As of now when one clicks the image it only toasts the image name. I want a user to be able to view the full image on click. Sorry to post all the code but its a desperate situation.</p>
  
  <p>RECYCLERVIEW CODE</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:id="@+id/activity_main"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".MainActivity"&gt;
  
      &lt;androidx.recyclerview.widget.RecyclerView
          android:id="@+id/recyclerview1"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>CARDVIEW CODE</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.cardview.widget.CardView
      xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:card_view="http://schemas.android.com/apk/res-auto"
      android:id="@+id/cardview1"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      card_view:cardElevation="5dp"
      card_view:contentPadding="5dp"
      card_view:cardCornerRadius="5dp"
      card_view:cardMaxElevation="5dp"
      &gt;
  
  
      &lt;RelativeLayout
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:background="#ECEFF1"&gt;
  
          &lt;com.android.volley.toolbox.NetworkImageView
              android:id="@+id/VolleyImageView"
              android:layout_width="150dp"
              android:layout_height="100dp"
              android:src="@mipmap/ic_launcher"
              android:layout_marginTop="10dp"
              android:layout_marginBottom="10dp"/&gt;
  
          &lt;TextView
              android:id="@+id/ImageNameTextView"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_centerVertical="true"
              android:layout_marginLeft="10dp"
              android:layout_toEndOf="@+id/VolleyImageView"
              android:layout_toRightOf="@+id/VolleyImageView"
              android:text="JSon Image Name"
              android:textColor="#000"
              android:textSize="15dp" /&gt;
  
  
      &lt;/RelativeLayout&gt;
  
  &lt;/androidx.cardview.widget.CardView&gt;
  </code></pre>
  
  <p>MAIN ACTIVITY</p>
  
  <pre><code>package com.ny.fetchallimages;
  
  import android.os.Bundle;
  import org.json.JSONArray;
  import java.util.ArrayList;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.JsonArrayRequest;
  import com.android.volley.toolbox.Volley;
  import java.util.List;
  
  import android.view.GestureDetector;
  import android.view.MotionEvent;
  import android.view.View;
  import android.widget.Toast;
  
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  
  import com.android.volley.RequestQueue;
  import com.android.volley.Response;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  public class MainActivity extends AppCompatActivity {
  
      List&lt;DataAdapter&gt; ListOfdataAdapter;
  
      RecyclerView recyclerView;
  
      String HTTP_JSON_URL = "http://*************.php";
  
      String Image_URL_JSON = "image_data";
  
      String Image_Name_JSON = "image_tag";
  
      JsonArrayRequest RequestOfJSonArray ;
  
      RequestQueue requestQueue ;
  
      View view ;
  
      int RecyclerViewItemPosition ;
  
      RecyclerView.LayoutManager layoutManagerOfrecyclerView;
  
      RecyclerView.Adapter recyclerViewadapter;
  
      ArrayList&lt;String&gt; ImageTitleNameArrayListForClick;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.activity_main);
  
          ImageTitleNameArrayListForClick = new ArrayList&lt;&gt;();
  
          ListOfdataAdapter = new ArrayList&lt;&gt;();
  
          recyclerView = (RecyclerView) findViewById(R.id.recyclerview1);
  
          recyclerView.setHasFixedSize(true);
  
          layoutManagerOfrecyclerView = new LinearLayoutManager(this);
  
          recyclerView.setLayoutManager(layoutManagerOfrecyclerView);
  
          JSON_HTTP_CALL();
  
          // Implementing Click Listener on RecyclerView.
          recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
  
              GestureDetector gestureDetector = new GestureDetector(MainActivity.this, new GestureDetector.SimpleOnGestureListener() {
  
                  @Override public boolean onSingleTapUp(MotionEvent motionEvent) {
  
                      return true;
                  }
  
              });
              @Override
              public boolean onInterceptTouchEvent(RecyclerView Recyclerview, MotionEvent motionEvent) {
  
                  view = Recyclerview.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
  
                  if(view != null &amp;&amp; gestureDetector.onTouchEvent(motionEvent)) {
  
                      //Getting RecyclerView Clicked Item value.
                      RecyclerViewItemPosition = Recyclerview.getChildAdapterPosition(view);
  
                      // Showing RecyclerView Clicked Item value using Toast.
                      Toast.makeText(MainActivity.this, ImageTitleNameArrayListForClick.get(RecyclerViewItemPosition), Toast.LENGTH_LONG).show();
                  }
  
                  return false;
              }
  
              @Override
              public void onTouchEvent(RecyclerView Recyclerview, MotionEvent motionEvent) {
  
              }
  
              @Override
              public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
  
              }
          });
  
  
      }
  
      public void JSON_HTTP_CALL(){
  
          RequestOfJSonArray = new JsonArrayRequest(HTTP_JSON_URL,
  
                  new Response.Listener&lt;JSONArray&gt;() {
                      @Override
                      public void onResponse(JSONArray response) {
  
                          ParseJSonResponse(response);
                      }
                  },
                  new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
  
                      }
                  });
  
          requestQueue = Volley.newRequestQueue(MainActivity.this);
  
          requestQueue.add(RequestOfJSonArray);
      }
  
      public void ParseJSonResponse(JSONArray array){
  
          for(int i = 0; i&lt;array.length(); i++) {
  
              DataAdapter GetDataAdapter2 = new DataAdapter();
  
              JSONObject json = null;
              try {
  
                  json = array.getJSONObject(i);
  
                  GetDataAdapter2.setImageTitle(json.getString(Image_Name_JSON));
  
                  // Adding image title name in array to display on RecyclerView click event.
                  ImageTitleNameArrayListForClick.add(json.getString(Image_Name_JSON));
  
                  GetDataAdapter2.setImageUrl(json.getString(Image_URL_JSON));
  
              } catch (JSONException e) {
  
                  e.printStackTrace();
              }
              ListOfdataAdapter.add(GetDataAdapter2);
          }
  
          recyclerViewadapter = new RecyclerViewAdapter(ListOfdataAdapter, this);
  
          recyclerView.setAdapter(recyclerViewadapter);
      }
  }
  </code></pre>
  
  <p>RECYCLERVIEWADAPTER</p>
  
  <pre><code>package com.ny.fetchallimages;
  
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  import com.android.volley.toolbox.NetworkImageView;
  
  import java.util.List;
  import com.android.volley.toolbox.ImageLoader;
  import android.content.Context;
  import android.view.LayoutInflater;
  import androidx.recyclerview.widget.RecyclerView;
  
  public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;RecyclerViewAdapter.ViewHolder&gt; {
  
      Context context;
  
      List&lt;DataAdapter&gt; dataAdapters;
  
      ImageLoader imageLoader;
  
      public RecyclerViewAdapter(List&lt;DataAdapter&gt; getDataAdapter, Context context){
  
          super();
          this.dataAdapters = getDataAdapter;
          this.context = context;
      }
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  
          View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview, parent, false);
  
          ViewHolder viewHolder = new ViewHolder(view);
  
          return viewHolder;
      }
  
      @Override
      public void onBindViewHolder(ViewHolder Viewholder, int position) {
  
          DataAdapter dataAdapterOBJ =  dataAdapters.get(position);
  
          imageLoader = ImageAdapter.getInstance(context).getImageLoader();
  
          imageLoader.get(dataAdapterOBJ.getImageUrl(),
                  ImageLoader.getImageListener(
                          Viewholder.VollyImageView,//Server Image
                          R.mipmap.ic_launcher,//Before loading server image the default showing image.
                          android.R.drawable.ic_dialog_alert //Error image if requested image dose not found on server.
                  )
          );
  
          Viewholder.VollyImageView.setImageUrl(dataAdapterOBJ.getImageUrl(), imageLoader);
  
          Viewholder.ImageTitleTextView.setText(dataAdapterOBJ.getImageTitle());
  
      }
  
      @Override
      public int getItemCount() {
  
          return dataAdapters.size();
      }
  
      class ViewHolder extends RecyclerView.ViewHolder{
  
          public TextView ImageTitleTextView;
          public NetworkImageView VollyImageView ;
  
          public ViewHolder(View itemView) {
  
              super(itemView);
  
              ImageTitleTextView = (TextView) itemView.findViewById(R.id.ImageNameTextView) ;
  
              VollyImageView = (NetworkImageView) itemView.findViewById(R.id.VolleyImageView) ;
  
          }
      }
  }
  </code></pre>
  
  <p>IMAGEADAPTER</p>
  
  <pre><code>package com.ny.fetchallimages;
  
  import android.graphics.Bitmap;
  import com.android.volley.toolbox.ImageLoader;
  import com.android.volley.RequestQueue;
  import android.content.Context;;
  import com.android.volley.toolbox.DiskBasedCache;
  import com.android.volley.Cache;
  import androidx.collection.LruCache;
  
  import com.android.volley.Network;
  import com.android.volley.toolbox.BasicNetwork;
  import com.android.volley.toolbox.HurlStack;
  
  public class ImageAdapter {
  
      public static ImageAdapter imageAdapter;
  
      public Network networkOBJ ;
  
      public RequestQueue requestQueue1;
  
      public ImageLoader Imageloader1;
  
      public Cache cache1 ;
  
      public static Context context1;
  
      LruCache&lt;String, Bitmap&gt; LRUCACHE = new LruCache&lt;String, Bitmap&gt;(30);
  
      private ImageAdapter(Context context) {
  
          this.context1 = context;
  
          this.requestQueue1 = RequestQueueFunction();
  
          Imageloader1 = new ImageLoader(requestQueue1, new ImageLoader.ImageCache() {
  
              @Override
              public Bitmap getBitmap(String URL) {
  
                  return LRUCACHE.get(URL);
              }
  
              @Override
              public void putBitmap(String url, Bitmap bitmap) {
  
                  LRUCACHE.put(url, bitmap);
              }
          });
      }
  
      public ImageLoader getImageLoader() {
  
          return Imageloader1;
      }
  
      public static ImageAdapter getInstance(Context SynchronizedContext) {
  
          if (imageAdapter == null) {
  
              imageAdapter = new ImageAdapter(SynchronizedContext);
          }
          return imageAdapter;
      }
  
      public RequestQueue RequestQueueFunction() {
  
          if (requestQueue1 == null) {
  
              cache1 = new DiskBasedCache(context1.getCacheDir());
  
              networkOBJ = new BasicNetwork(new HurlStack());
  
              requestQueue1 = new RequestQueue(cache1, networkOBJ);
  
              requestQueue1.start();
          }
          return requestQueue1;
      }
  }
  </code></pre>
  
  <p>DATAADAPTER</p>
  
  <pre><code>package com.ny.fetchallimages;
  
  public class DataAdapter
  {
      public String ImageURL;
      public String ImageTitle;
  
      public String getImageUrl() {
  
          return ImageURL;
      }
  
      public void setImageUrl(String imageServerUrl) {
  
          this.ImageURL = imageServerUrl;
      }
  
      public String getImageTitle() {
  
          return ImageTitle;
      }
  
      public void setImageTitle(String Imagetitlename) {
  
          this.ImageTitle = Imagetitlename;
      }
  
  }
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/TYylZ.png" alt="enter image description here"></p>