title: add image to first cell in gridview
body: <p>I've a gridview which displays images and text from web service using pojo. I want to add an image (with no text) before all the other images (as 1st item). This image should be available even when there are no images from web service i.e. if server database has no images.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>GridView Adapter
  
  public class GridViewAdapter extends ArrayAdapter&lt;GridItem&gt; {
  
      private Context mContext;
      private int resource;
      private ArrayList&lt;GridItem&gt; mGridData = new ArrayList&lt;GridItem&gt;();
  
      public GridViewAdapter(Context mContext, int resource, ArrayList&lt;GridItem&gt; mGridData) {
          super(mContext, resource, mGridData);
          this.resource = resource;
          this.mContext = mContext;
          this.mGridData = mGridData;
      }
  
      public void setGridData(ArrayList&lt;GridItem&gt; mGridData) {
          this.mGridData = mGridData;
          notifyDataSetChanged();
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View v = convertView;
          ViewHolder holder = null;
          if (v == null) {
  
              LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
              v = inflater.inflate(resource, parent, false);
              holder = new ViewHolder();
  
              holder.image = (ImageView) v.findViewById(R.id.item_image);
              holder.date = (TextView) v.findViewById(R.id.item_date);
              holder.month = (TextView) v.findViewById(R.id.item_month);
  
              v.setTag(holder);
          } else {
              holder = (ViewHolder) v.getTag();
  
          }
  
          GridItem item = mGridData.get(position);
  
          Picasso
                  .with(mContext)
                  .load(item.getImage())
                  .placeholder(R.drawable.placeholder)
                  .fit()
                  .into(holder.image);
  
          holder.date.setText(item.getDate());
          holder.month.setText(item.getMonth());
  
          return v;
      }
  
      class ViewHolder {
          ImageView image;
          TextView date;
          TextView month;
      }
  
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>POJO
  
  public class GridItem {
  
      private String textDateUrls, textMonthUrls;
      private String imageUrls;
  
      public GridItem() {
          super();
      }
  
      public String getImage() {
          return imageUrls;
      }
  
      public void setImage(String imageUrls) {
          this.imageUrls = imageUrls;
      }
  
      public String getDate() {
          return textDateUrls;
      }
  
      public void setDate(String textDateUrls) {
          this.textDateUrls = textDateUrls;
      }
  
      public String getMonth() {
          return textMonthUrls;
      }
  
      public void setMonth(String textMonthUrls) {
          this.textMonthUrls = textMonthUrls;
      }
  
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>Main Activity
  
  public class MainActivity extends AppCompatActivity {
  
      private GridView mGridView;
      private GridItem newItem;
      private GridViewAdapter mGridAdapter;
      private ArrayList&lt;GridItem&gt; mGridData;
      public static final String KEY_USERID = "user_id";
      private static final String REGISTER_URL = "http://staging.techunits.com/android_login_api/Services.php?action=fetchUserLog";
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState){
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          mGridView = (GridView)findViewById(R.id.gridView);
          registerUser();
  
          mGridData = new ArrayList&lt;&gt;();
          mGridAdapter = new GridViewAdapter(this, R.layout.profile_gridview_item, mGridData);
          mGridView.setAdapter(mGridAdapter);
          newItem = new GridItem();
          String imageUri = "drawable://" + R.mipmap.ic_add;
          //mGridData.add(0, newItem);
  
  
      }
  
  
      private void registerUser(){
  
          StringRequest stringRequest = new StringRequest(Request.Method.POST, REGISTER_URL,
                  new Response.Listener&lt;String&gt;() {
                      @Override
                      public void onResponse(String response) {
  
                          try {
                              JSONObject jObj = new JSONObject(response);
                              String status = jObj.getString("status");
  
                              // Now check status value
                              if (status.equals("0")) {
  
                                  Toast.makeText(getApplicationContext(), "There was some error! Please try again.", Toast.LENGTH_LONG).show();
  
                              }else if(status.equals("1")){
  
                                  mGridAdapter.setGridData(mGridData);
  
                                  JSONArray result = jObj.getJSONArray("results");
                                  GridItem item;
                                  for(int i = 0 ; i &lt;result.length() ; i++){
                                      JSONObject json_data = result.getJSONObject(i);
  
                                      String image = json_data.getString("images");
                                      String date = json_data.getString("date");
  
                                      item = new GridItem();
                                      item.setImage(image);
                                      item.setDate(date);
                                      mGridData.add(item);
                                  }
  
  
  
  
  
                              } else {
                                  // Error in login. Get the error message
                                  String errorMsg = jObj.getString("error_msg");
                                  Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
                              }
                          } catch (JSONException e) {
                              // JSON error
                              e.printStackTrace();
                              Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
                          }
  
  
  
                      }
                  },
                  new Response.ErrorListener() {
                      @Override
                      public void onErrorResponse(VolleyError error) {
                          Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_LONG).show();
                      }
                  }){
              @Override
              protected Map&lt;String,String&gt; getParams(){
                  Map&lt;String,String&gt; params = new HashMap&lt;String, String&gt;();
                  params.put(KEY_USERID, "21");
                  return params;
              }
  
          };
  
          RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
          requestQueue.add(stringRequest);
      }
  
  
  
  
  }</code></pre>
  </div>
  </div>
  </p>