Ejemplo n.º 1
0
  @Override
  protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    try {
      final Connection thisConnection = app.getAllConnections().get(position);

      // set the current connection
      app.setCurrentConnection(thisConnection);

      // go to the connection screen
      Intent intent = new Intent(MainMenu.this, ConnectionDetails.class);
      startActivity(intent);
    } catch (Exception e) {
      Toast.makeText(this, getString(R.string.create_connection), 1500).show();
      e.printStackTrace();
    }
  }
Ejemplo n.º 2
0
  private void populateList() {
    // intialize array of choices
    String[] connections;
    connections = null;

    // try to retrieve the local staff / users
    try {

      // do the retrieval
      app.retrieveAllConnections();

      // check to see if there are any
      if (app.getAllConnections().size() > 0) {
        // sort the fist by staff first name
        Collections.sort(
            app.getAllConnections(),
            new Comparator<Connection>() {

              public int compare(Connection lhs, Connection rhs) {
                Connection p1 = (Connection) lhs;
                Connection p2 = (Connection) rhs;
                return p1.getName().compareTo(p2.getName());
              }
            });

        // connections ready to go
        connections = new String[app.getAllConnections().size()];
        for (Connection connection : app.getAllConnections()) {
          connections[app.getAllConnections().indexOf(connection)] =
              connection.getName() + "\n" + connection.getTextURL();
        }

      } else {
        // no users in the local db
        connections = new String[1];
        connections[0] = getString(R.string.no_connections);
        Toast toast = Toast.makeText(this, getString(R.string.no_connections), 1500);
        toast.show();
      }

    } catch (Exception e) {
      // no user/staff data in application yet. call for a refresh
      connections = new String[1];
      connections[0] = getString(R.string.no_connections);
    }

    setListAdapter(new ArrayAdapter<String>(this, R.layout.connection_item, connections));

    ListView lv = getListView();
    lv.setTextFilterEnabled(true);
  }