Ejemplo n.º 1
0
  /*
   * @see
   * http://android-developers.blogspot.com/2011/09/androids-http-clients.html
   */
  public void showStopPassingLines(int stopid) {
    StringBuilder msgstr = new StringBuilder();

    /* Create the Database (no Errors if it already exists) */
    // dbhelper = new DataBaseHelper(this);

    SQLiteDatabase myDB = dbhelper.getMyWritableDatabase();

    try {
      /* Query for some results with Selection and Projection. */

      Cursor c =
          myDB.rawQuery(
              myResources.getString(R.string.sql_select_linespassing), new String[] {"" + stopid});

      /* Get the indices of the Columns we will need */
      int numColumn = c.getColumnIndex("busnum");
      int nameColumn = c.getColumnIndex("busname");

      /* Check if our result was valid. */
      if (c != null) {

        /* Check if our result was valid. */
        if (c != null) {
          if (c.moveToFirst()) {
            do {
              String busnum = c.getString(numColumn);
              String busname = c.getString(nameColumn);

              // append the message that shows the number and
              // the name of the passing bus line
              msgstr.append(busnum).append(". ").append(busname).append("\n");

            } while (c.moveToNext());
          }
        }
      }

      // close cursor
      c.close();

      AlertDialog alertDialog1 = new AlertDialog.Builder(this).create();
      alertDialog1.setTitle(myResources.getString(R.string.msg_passinglines));
      alertDialog1.setMessage(msgstr);
      alertDialog1.setButton(
          "OK",
          new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
              // TODO Auto-generated method stub

            }
          });
      alertDialog1.setIcon(R.drawable.icon);
      alertDialog1.show();
    } catch (SQLiteException e) {
      android.util.Log.e("Database error", e.getLocalizedMessage());
    } finally {
      if (myDB != null) myDB.close();
      dbhelper.close();
    }
    // http://www.anddev.org/code-snippets-for-android-f33/autocompletetextview-cursoradapter-t12430.html
  }
Ejemplo n.º 2
0
  public void loadStopsList() {
    String busStopStr[];

    /* Create the Database (no Errors if it already exists) */
    // dbhelper = new DataBaseHelper(this);

    try {
      dbhelper.createDataBase();

    } catch (IOException ioe) {
      throw new Error("Unable to create database");
    }

    SQLiteDatabase myDB = dbhelper.getMyWritableDatabase();

    try {
      /* Query for some results with Selection and Projection. */

      // Cursor c = myDB
      // .rawQuery(
      // "select v_stop.stopid as stopid , v_stop.sorder || '. ' || v_stop.stopname as stopstr,
      // v_stop.routeid as routeid "
      // + " from v_stop  where v_stop.direction = "
      // + selDirection
      // + " and v_stop.lineid = "
      // + selLineid, null);
      Cursor c =
          myDB.rawQuery(
              myResources.getString(R.string.sql_select_stops),
              new String[] {selDirection + "", selLineid + ""});

      /* Get the indices of the Columns we will need */
      int idColumn = c.getColumnIndex("stopid");
      int strColumn = c.getColumnIndex("stopstr");
      // int routeIDColumn = c.getColumnIndex("routeid");

      busStopStr = new String[1];
      busStopsId = new int[1];

      /* Check if our result was valid. */
      if (c != null) {
        /* Check if at least one Result was returned. */
        busStopStr = new String[c.getCount()];
        busStopsId = new int[c.getCount()];

        if (c.moveToFirst()) {
          int i = 0;
          // selRouteid = c.getInt(routeIDColumn);

          do {
            busStopStr[i] = c.getString(strColumn);
            busStopsId[i++] = c.getInt(idColumn);

            // android.util.Log.d("Line :", "Position: " + (i -
            // 1)
            // + " " + qID + " " + qStr);
          } while (c.moveToNext());
        }
      }

      // close cursor
      c.close();

      setListAdapter(
          new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, busStopStr));

    } catch (SQLiteException e) {
      android.util.Log.e("Database error", e.getLocalizedMessage());
    } finally {
      if (myDB != null) myDB.close();
      dbhelper.close();
    }
  }