title: Sort Image according to DATE and TIME inside gridview android
body: <p>//The Path where my images are saving </p>
  
  <p>/storage/emulated/0/Pictures/CameraExample/JPEG_20150107_152640.jpeg</p>
  
  <p>//This is one of the file path.</p>
  
  <p>//I need to sort images like last taken photo as the first one to display //inside the grid view as of now images are displayed, recent photo at the //last.</p>
  
  <p>Below is my code</p>
  
  <pre><code> public class ImageAdapter extends BaseAdapter{
  
  
          private Context context;
          private int imageWidth;
          private Activity activity;
          ArrayList&lt;String&gt; itemList = new ArrayList&lt;String&gt;();
          Bitmap bitmap;
  
          public ImageAdapter(Activity activity,ArrayList&lt;String&gt; itemList,int imageWidth) {
              this.activity = activity;
              this.itemList = itemList;
              this.imageWidth = imageWidth;
  
          }
  
          @Override
          public int getCount() {
  
              return this.itemList.size();
          }
  
          void add(String path) {
              itemList.add(path);
  
          }
  
          @Override
          public Object getItem(int position) {
              return this.itemList.get(position);
          }
  
          @Override
          public long getItemId(int position) {
              return position;
          }
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              ImageView imageView;
  
              if (convertView == null) {
  
                  imageView = new ImageView(activity);
  
  
              }
          else {
                  imageView = (ImageView) convertView;
  
              }
  
              imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
  
              imageView.setLayoutParams(new GridView.LayoutParams(imageWidth ,imageWidth ));
  
  
              bitmap = decodeFile(itemList.get(position), imageWidth, imageWidth);
  
               imageView.setImageBitmap(bitmap);
  
              imageView.setOnClickListener( new OnImageClickListener(position));
  
  
              return imageView;
          }
  
  
          class OnImageClickListener implements View.OnClickListener {
  
              int position;
  
              public OnImageClickListener(int position){
                  this.position = position;
              }
  
              @Override
              public void onClick(View v) {
                  Intent intent = new Intent(activity, ImageDisplayActivity.class);               
  
                  intent.putExtra("position", position);    
  
                  Log.d("ImageAdapter","Intent.putExtra ");
                  activity.startActivity(intent);
  
              }
          }
  
          public Bitmap decodeFile(String path, int reqWidth, int reqHeight) {
              try {
                  File f = new File(path);     
                  BitmapFactory.Options o = new BitmapFactory.Options();
  
                  o.inJustDecodeBounds = true;
                  BitmapFactory.decodeStream(new FileInputStream(f), null, o);
                  final int REQUIRED_WIDTH = reqWidth;
                  final int REQUIRED_HEIGHT = reqHeight;
                  int scale = 1;
                  while (o.outWidth / scale / 2 &gt;= REQUIRED_WIDTH &amp;&amp; o.outHeight / scale / 2 &gt;= REQUIRED_HEIGHT)
                      scale *= 2;
  
                  BitmapFactory.Options o2 = new BitmapFactory.Options();
                  o2.inSampleSize = scale;
                  return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
  
              } catch (FileNotFoundException e) {
                  e.printStackTrace();
              }
              return null;
          }
      }
  </code></pre>
  
  <p>// And Finally when I scroll my grid view . Scrolling is not so smooth. Please help me in solving two problems.</p>
  
  <p>// My GridView Activity Class</p>
  
  <pre><code>public class GridViewActivity extends Activity {
  
      private ImageAdapter imageAdapter;
      private HelperUtils utils;
      private ArrayList&lt;String&gt; itemList = new ArrayList&lt;String&gt;();
      private GridView gridView;
      private int columnWidth;
      private Activity activity;
  
  
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_gridview);
  
          gridView = (GridView) findViewById(R.id.gridView);
  
          utils = new HelperUtils(this);
  
          InitilizeGridLayout();
  
          itemList = utils.getFilePaths();
  
          imageAdapter = new ImageAdapter(this, itemList, columnWidth);
  
          gridView.setAdapter(imageAdapter);
  
      }
  
      private void InitilizeGridLayout() {
  
          Resources r = getResources();
          float padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, HelperAppConstant.GRID_PADDING, r.getDisplayMetrics());
          columnWidth = (int) ((utils.getScreenWidth() - ((HelperAppConstant.NUM_OF_COLUMNS + 1) * padding)) / HelperAppConstant.NUM_OF_COLUMNS);
  
          gridView.setNumColumns(HelperAppConstant.NUM_OF_COLUMNS);
          gridView.setColumnWidth(columnWidth);
          gridView.setStretchMode(GridView.NO_STRETCH);
          gridView.setPadding((int) padding, (int) padding, (int) padding, (int) padding);
          gridView.setHorizontalSpacing((int) padding);
          gridView.setVerticalSpacing((int) padding);
  
  
      }
  }
  </code></pre>