コード例 #1
0
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
      return true;
    }

    if (id == R.id.confirm_create_group) {
      if (groupNameText.getText().toString().length() > 0
          && cityText.getText().toString().length() > 0) {
        nome = groupNameText.getText().toString();
        city = cityText.getText().toString();
        int selectedId = groupType.getCheckedRadioButtonId();
        if (selectedId == R.id.group_closed_radio) aperto = false;

        InfoGruppoBean gruppoBean = new InfoGruppoBean();
        gruppoBean.setNome(nome);
        gruppoBean.setCitta(city);
        gruppoBean.setAperto(aperto);
        if (checkNetwork())
          new CreaGruppoAT(getApplicationContext(), this, this, idSessione, gruppoBean).execute();

      } else {
        Toast.makeText(getApplicationContext(), "Compilare tutti i campi!", Toast.LENGTH_LONG)
            .show();
      }
    }

    return super.onOptionsItemSelected(item);
  }
コード例 #2
0
  private void AlterAdapterGroups() {
    // Se l'utente svuota l'edittext, mostro tutti i gruppi aperti esistenti
    if (nameCapture.getText().toString().isEmpty()) {
      partialNames.clear();
      partialTypes.clear();
      partialCities.clear();
      partialIds.clear();

      groupslist.clear();

      for (int i = 0; i < nomigruppi.length; i++) {
        partialNames.add(i, nomigruppi[i]);
        partialCities.add(i, citta[i]);
        partialTypes.add(i, aperti[i]);
        partialIds.add(i, ids[i]);

        InfoGruppoBean g = new InfoGruppoBean();
        g.setNome(nomigruppi[i]);
        g.setAperto(aperti[i]);
        g.setCitta(citta[i]);
        g.setId(ids[i]);
        groupslist.add(g);
      }
      adapterGroups.notifyDataSetChanged();
    } else {

      partialNames.clear();
      partialTypes.clear();
      partialCities.clear();
      partialIds.clear();

      groupslist.clear();
      int j = 0;
      for (int i = 0; i < nomigruppi.length; i++) {
        // ToUpperCase per fare ricerca case-insensitive
        if (nomigruppi[i]
            .toString()
            .toUpperCase()
            .contains(nameCapture.getText().toString().toUpperCase())) {
          partialNames.add(j, nomigruppi[i]);
          partialCities.add(j, citta[i]);
          partialTypes.add(j, aperti[i]);
          partialIds.add(j, ids[i]);

          InfoGruppoBean g = new InfoGruppoBean();
          g.setNome(nomigruppi[i]);
          g.setAperto(aperti[i]);
          g.setCitta(citta[i]);
          g.setId(ids[i]);
          groupslist.add(g);
          j++;
        } else continue;
        adapterGroups.notifyDataSetChanged();
      }
    }

    if (adapterGroups.getCount() == 0) {
      emptyText.setVisibility(View.VISIBLE);
      emptyText.setText("Nessun gruppo aperto trovato.");
    }
  }