title: Android staggered gridview implementation
body: <p>I am trying to implement the staggered grid view library. I am using an approach similar to the normal gridview implementation like this:</p>
  
  <pre><code>package com.example.abcd8;
  
  import com.origamilabs.library.views.StaggeredGridView;
  
  import android.os.Bundle;
  import android.app.Activity;
  import android.view.Menu;
  import android.widget.GridView;
  
  public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          StaggeredGridView sg1=(StaggeredGridView)findViewById(R.id.staggeredGridView1);
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  }
  </code></pre>
  
  <p>and adapter is this</p>
  
  <pre><code>package com.example.abcd8;
  
  import android.content.Context;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;
  
  public class ImageAdapter extends BaseAdapter {
  
      private Context ctx;
  
      public ImageAdapter(Context c)
      {
          ctx=c;
      }
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
          return pics.length;
      }
  
      @Override
      public Object getItem(int position) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return 0;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          // TODO Auto-generated method stub
          ImageView iv;
          if (convertView == null) {  // if it's not recycled, initialize some attributes
              iv = new ImageView(ctx);
              iv.setLayoutParams(new GridView.LayoutParams(150,150));
              iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
              iv.setPadding(8, 8, 8, 8);
          } else {
              iv = (ImageView) convertView;
          }
          iv.setImageResource(pics[position]);
          return iv;
  
      }
  
      private Integer[] pics={
              R.drawable.sample_0,R.drawable.sample_1,
              R.drawable.sample_2,R.drawable.sample_3,
              R.drawable.sample_4,R.drawable.sample_5,
              R.drawable.sample_6,R.drawable.sample_7
      };
      }
  </code></pre>
  
  <p>and the xml code is this</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      xmlns:staggered="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:id="@+id/mainLayout"&gt;
  
      &lt;com.origamilabs.library.views.StaggeredGridView
          android:id="@+id/staggeredGridView1"
          staggered:numColumns="2"
          staggered:drawSelectorOnTop="true"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>But this doesnt work as i think we need to use a staggeredadapter here to add the images. I am not sure how to use it in this case and how to add it to my code. 
  Please help me out here
  Thanks</p>