@Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listview_main);
    try {
      sr_llayout = (LinearLayout) findViewById(R.id.sr_layout);
      linflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

      /* Create a DBAdapter object and set up a connection */
      sr_datasource = new DBAdapter(this);
      sr_datasource.open();

      /* Create a cursor for the database search results */
      mCursor_sresults = sr_datasource.getSearchResults();

      int rideid_col = mCursor_sresults.getColumnIndex("s_rideid");
      int usrid_col = mCursor_sresults.getColumnIndex("s_usrid");
      int from_col = mCursor_sresults.getColumnIndex("s_ridefrom");
      int to_col = mCursor_sresults.getColumnIndex("s_rideto");
      int radius_col = mCursor_sresults.getColumnIndex("s_radius");

      if (mCursor_sresults != null) {

        /* Check if at least one result was returned. */
        if (mCursor_sresults.moveToFirst()) {
          int i = 0;

          /* Loop through all the results */
          do {
            i++;

            /* Map the layout of the customlist_viewitem xml file */
            custom_view = linflater.inflate(R.layout.customlist_viewitem, null);
            tv_email = (TextView) custom_view.findViewById(R.id.txt_email01);
            tv_from = (TextView) custom_view.findViewById(R.id.txt_from02);
            tv_to = (TextView) custom_view.findViewById(R.id.txt_to03);
            tv_dist = (TextView) custom_view.findViewById(R.id.txt_dist04);
            button_details = (Button) custom_view.findViewById(R.id.btn_details01);

            tv_email.setId(i);
            tv_from.setId(i);
            tv_to.setId(i);
            tv_dist.setId(i);
            button_details.setId(i);

            /* Set the text to be displayed to the user */
            tv_email.setText("   Email ->  " + mCursor_sresults.getString(usrid_col));
            tv_from.setText("   From -> " + mCursor_sresults.getString(from_col));
            tv_to.setText("   To -> " + mCursor_sresults.getString(to_col));
            Double dist =
                Double.parseDouble(
                    new DecimalFormat("#.##").format(mCursor_sresults.getDouble(radius_col)));
            str_rideid = mCursor_sresults.getString(rideid_col);
            str_usrid = mCursor_sresults.getString(usrid_col);
            tv_dist.setText("   Dist -> " + dist + " miles");
            button_details.setText(">>");

            /* If details button is clicked then invoke the ConfirmRideActivity
            which will list the carpool host details */
            button_details.setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                    Intent goto_confirmride =
                        new Intent(DynamicListActivity.this, ConfirmRideActivity.class);
                    goto_confirmride.putExtra("usrid", str_usrid);
                    goto_confirmride.putExtra("rideid", str_rideid);
                    startActivity(goto_confirmride);
                  }
                });
            sr_llayout.addView(custom_view);

          } while (mCursor_sresults.moveToNext());
        }
      }
      mCursor_sresults.close();
      sr_datasource.close();
    } catch (Exception e) {
      Log.e("Dynamic List Activity:", e.toString());
    }
  };
        @Override
        public void onClick(View arg0) {
          try {
            /* Open Database */
            gr_datasource.open();
            /* Get from and to address from autocomplete fields */
            gr_frm_addr = gr_frm_acView.getText().toString();
            gr_to_addr = gr_to_acView.getText().toString();

            flag = 0;
            /* Checking if FROM and TO address is empty */
            if (gr_frm_addr.length() == 0) {
              gr_frm_acView.setError("Enter from address");
              flag = 1;
            } else if (gr_to_addr.length() == 0) {
              gr_to_acView.setError("Enter to address");
              flag = 1;
            }
            /* Radius validation */
            String str_radius = et_radius.getText().toString();
            if (str_radius.length() == 0) {
              et_radius.setError("Enter valid radius");
              flag = 1;
            } else {
              rad_value = Integer.valueOf(et_radius.getText().toString());
              if (rad_value < 0 || rad_value > 20) {
                et_radius.setError("Limit 20 miles");
                flag = 1;
              }
            }
            /* Cost Validation */
            String str_cost = et_cost.getText().toString();
            if (str_cost.length() == 0) {
              et_cost.setError("Enter valid cost");
              flag = 1;
            } else {
              cost_value = Float.valueOf(et_cost.getText().toString());
              if (cost_value < 0 || cost_value > 1000) {
                et_cost.setError("Limit 1000 dollars");
                flag = 1;
              }
            }

            if (flag == 0) {
              /* Function call to calculate lattitudes and longitudes for FROM address */
              jsonObject_main_frm = getLocationInfo(gr_frm_addr);
              frm_lattitude = getLattitude(jsonObject_main_frm);
              frm_longitude = getLongitude(jsonObject_main_frm);

              /* Function call to calculate lattitudes and longitudes for TO address */
              jsonObject_main_to = getLocationInfo(gr_to_addr);
              to_lattitude = getLattitude(jsonObject_main_to);
              to_longitude = getLongitude(jsonObject_main_to);

              str_date = datePicker.getText().toString();
              /* Convert time to milliseconds */
              time = dateTime.getTimeInMillis();
              /* Insert into RIDEDETAILS table */
              long id;
              id =
                  gr_datasource.insertridedetails(
                      str_usrid,
                      gr_frm_addr,
                      gr_to_addr,
                      rad_value,
                      str_date,
                      time,
                      selected_seat,
                      cost_value,
                      frm_lattitude,
                      frm_longitude,
                      to_lattitude,
                      to_longitude);
              /* Close database object */
              gr_datasource.close();

              /* On inserting Ride Details redirect to choose ride screen or exit */
              AlertDialog.Builder alertDialogBuilder =
                  new AlertDialog.Builder(PlacesAutoCompleteActivity.this);
              alertDialogBuilder.setTitle("Ride 'n Divide");
              alertDialogBuilder
                  .setMessage("Thank you, for giving a ride! Do you want to check other rides?")
                  .setCancelable(false)
                  .setPositiveButton(
                      "Check Rides",
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                          Intent reselect =
                              new Intent(PlacesAutoCompleteActivity.this, ChooseRideActivity.class);
                          reselect.putExtra("usrid", str_usrid);
                          startActivity(reselect);
                        }
                      })
                  .setNegativeButton(
                      "Exit",
                      new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                          dialog.cancel();
                          PlacesAutoCompleteActivity.this.finish();
                        }
                      });

              AlertDialog alertDialog = alertDialogBuilder.create();
              alertDialog.show();
            }

          } catch (Exception e) {
            Log.e("Places AutoComplete Activity buttonsubmit:", e.toString());
          }
        }