title: Store data in mysql from recyclerview with button using volley
body: <p>I am working on app that fetches data using volley and displays in feed using recyclerview.i have a button in each card that when clicked, will count the number of clicks and display it in a textview in that particular card(like instagram like button). Now i want the value of clicks to also be stored in a mysql database when the button is clicked. can anyone PLEASE help me with how i can go about this?THis is my code</p>
  
  <p>CARD ADAPTER</p>
  
  <pre><code>import android.content.Context;
  import android.media.Image;
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.ImageButton;
  import android.widget.ProgressBar;
  import android.widget.TextView;
  import com.android.volley.toolbox.ImageLoader;
  import com.android.volley.toolbox.NetworkImageView;
  import org.w3c.dom.Text;
  import java.util.ArrayList;
  import java.util.List;
  
  /**
   * Created by Belal on 11/9/2015.
   */
  public class CardAdapter extends RecyclerView.Adapter&lt;CardAdapter.ViewHolder&gt; {
      //Imageloader to load image
      private ImageLoader imageLoader;
      private Context context;
  
      //List to store all superheroes
      List&lt;SuperHero&gt; superHeroes;
  
      //Constructor of this class
      public CardAdapter(List&lt;SuperHero&gt; superHeroes, Context context) {
          super();
          //Getting all superheroes
          this.superHeroes = superHeroes;
          this.context = context;
      }
  
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View v = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.superheroes_list, parent, false);
          ViewHolder viewHolder = new ViewHolder(v);
          return viewHolder;
      }
  
      @Override
      public void onBindViewHolder( final ViewHolder holder,    final int position) {
          //Getting the particular item from the list
            final SuperHero superHero = superHeroes.get(position);
  
          //Loading image from url
          imageLoader = CustomVolleyRequest.getInstance(context).getImageLoader();
          imageLoader.get(superHero.getImageUrl(), ImageLoader.getImageListener(holder.imageView, R.drawable.image, android.R.drawable.ic_dialog_alert));
  
          //Showing data on the views
          holder.imageView.setImageUrl(superHero.getImageUrl(), imageLoader);
          holder.textViewName.setText(superHero.getName());
          holder.textViewPublisher.setText(superHero.getPublisher());
          holder.textViewLikes.setText(superHero.getLikes());
  
  
  
          holder.custom_button.setOnClickListener(new View.OnClickListener() {
              int count;
  
  
              @Override
              public void onClick(View v) {
  
                  count = 0;
  
                  superHeroes.get(position).setCount(superHeroes.get(position).getCount() + 1);
                  holder.txtCount.setText(superHeroes.get(position).getCount() + "");
  
  
              }
  
          });
  
  
  
      }
      @Override
      public int getItemCount() {
          return superHeroes.size();
      }
  
      class ViewHolder extends RecyclerView.ViewHolder {
          //Views
          public NetworkImageView imageView;
          public TextView textViewName;
          public TextView textViewPublisher;
          public TextView textViewLikes;
          public TextView txtCount;
          public ImageButton custom_button;
  
          //Initializing Views
          public ViewHolder(View itemView) {
              super(itemView);
              imageView = (NetworkImageView) itemView.findViewById(R.id.imageViewHero);
              textViewName = (TextView) itemView.findViewById(R.id.textViewName);
              textViewPublisher = (TextView) itemView.findViewById(R.id.textViewPublisher);
              textViewLikes = (TextView) itemView.findViewById(R.id.textViewlikes);
              txtCount = (TextView) itemView.findViewById(R.id.txtCount);
              custom_button = (ImageButton) itemView.findViewById(R.id.custom_button);
          }
      }
  }
  </code></pre>
  
  <p>MAINACTIVITY</p>
  
  <pre><code>import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  
  import android.view.View;
  import android.widget.ProgressBar;
  import android.widget.TextView;
  import android.widget.Toast;
  
  
  import com.android.volley.Request;
  import com.android.volley.RequestQueue;
  import com.android.volley.Response;
  import com.android.volley.VolleyError;
  import com.android.volley.toolbox.JsonArrayRequest;
  import com.android.volley.toolbox.StringRequest;
  import com.android.volley.toolbox.Volley;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  
  public class MainActivity extends AppCompatActivity implements RecyclerView.OnScrollChangeListener {
  
  
  
      //Creating a List of superheroes
      private List&lt;SuperHero&gt; listSuperHeroes;
  
      //Creating Views
      private RecyclerView recyclerView;
      private RecyclerView.LayoutManager layoutManager;
      private RecyclerView.Adapter adapter;
  
      //Volley Request Queue
      private RequestQueue requestQueue;
      //The request counter to send ?page=1, ?page=2  requests
      private int requestCount = 1;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          //Initializing Views
          recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
          recyclerView.setHasFixedSize(true);
          layoutManager = new LinearLayoutManager(this);
          recyclerView.setLayoutManager(layoutManager);
  
          //Initializing our superheroes list
          listSuperHeroes = new ArrayList&lt;&gt;();
          requestQueue = Volley.newRequestQueue(this);
  
          //Calling method to get data to fetch data
          getData();
  
          //Adding an scroll change listener to recyclerview
          recyclerView.setOnScrollChangeListener(this);
  
          //initializing our adapter
          adapter = new CardAdapter(listSuperHeroes, this);
  
          //Adding adapter to recyclerview
          recyclerView.setAdapter(adapter);
  
  
      }
  
  
      //Request to get json from server we are passing an integer here
      //This integer will used to specify the page number for the request ?page = requestcount
      //This method would return a JsonArrayRequest that will be added to the request queue
  
      private JsonArrayRequest getDataFromServer(int requestCount) {
          //Initializing ProgressBar
          final ProgressBar progressBar = (ProgressBar) findViewById(R.id.progressBar1);
  
          //Displaying Progressbar
          progressBar.setVisibility(View.VISIBLE);
          setProgressBarIndeterminateVisibility(true);
  
          //JsonArrayRequest of volley
          JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Config.DATA_URL + String.valueOf(requestCount),
                  new Response.Listener&lt;JSONArray&gt;() {
                      @Override
                      public void onResponse(JSONArray response) {
                          //Calling method parseData to parse the json response
                          parseData(response);
                          //Hiding the progressbar
                          progressBar.setVisibility(View.GONE);
                      }
                  },
                  new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          progressBar.setVisibility(View.GONE);
                          //If an error occurs that means end of the list has reached
                          Toast.makeText(MainActivity.this, "No More Items Available", Toast.LENGTH_SHORT).show();
                      }
                  });
  
          //Returning the request
          return jsonArrayRequest;
      }
  
  
  
      //This method will get data from the web api
      private void getData() {
          //Adding the method to the queue by calling the method getDataFromServer
          requestQueue.add(getDataFromServer(requestCount));
          //Incrementing the request counter
          requestCount++;
      }
  
      //This method will parse json data
      private void parseData(JSONArray array) {
          for (int i = 0; i &lt; array.length(); i++) {
              //Creating the superhero object
              SuperHero superHero = new SuperHero();
              JSONObject json = null;
              try {
                  //Getting json
                  json = array.getJSONObject(i);
  
                  //Adding data to the superhero object
                  superHero.setImageUrl(json.getString(Config.TAG_IMAGE_URL));
                  superHero.setName(json.getString(Config.TAG_NAME));
                  superHero.setPublisher(json.getString(Config.TAG_PUBLISHER));
                  superHero.setLikes(json.getString(Config.TAG_LIKES));
  
              } catch (JSONException e) {
                  e.printStackTrace();
              }
              //Adding the superhero object to the list
              listSuperHeroes.add(superHero);
          }
  
          //Notifying the adapter that data has been added or changed
          adapter.notifyDataSetChanged();
      }
  
  
  
  
      //This method would check that the recyclerview scroll has reached the bottom or not
      private boolean isLastItemDisplaying(RecyclerView recyclerView) {
          if (recyclerView.getAdapter().getItemCount() != 0) {
              int lastVisibleItemPosition = ((LinearLayoutManager) recyclerView.getLayoutManager()).findLastCompletelyVisibleItemPosition();
              if (lastVisibleItemPosition != RecyclerView.NO_POSITION &amp;&amp; lastVisibleItemPosition == recyclerView.getAdapter().getItemCount() - 1)
                  return true;
          }
          return false;
      }
  
      //Overriden method to detect scrolling
      @Override
      public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
          //Ifscrolled at last then
          if (isLastItemDisplaying(recyclerView)) {
  
              //Calling the method getdata again
              getData();
          }
      }
  }
  </code></pre>