@Override
 public boolean onActionItemClicked(final ActionMode mode, final MenuItem item) {
   final ListView listView = getListView();
   switch (item.getItemId()) {
     case R.id.delete:
       {
         final Expression where =
             Expression.in(
                 new Column(Filters._ID), new RawItemArray(listView.getCheckedItemIds()));
         mResolver.delete(getContentUri(), where.getSQL(), null);
         break;
       }
     case R.id.inverse_selection:
       {
         final SparseBooleanArray positions = listView.getCheckedItemPositions();
         for (int i = 0, j = listView.getCount(); i < j; i++) {
           listView.setItemChecked(i, !positions.get(i));
         }
         return true;
       }
     default:
       {
         return false;
       }
   }
   mode.finish();
   return true;
 }
  private void saveAndFinish() {
    String selectedCategories = "";

    SparseBooleanArray selectedItems = lv.getCheckedItemPositions();
    List<Integer> rCheckedItems = new Vector<Integer>();

    for (int i = 0; i < selectedItems.size(); i++) {
      if (selectedItems.get(selectedItems.keyAt(i)) == true) {
        rCheckedItems.add(selectedItems.keyAt(i));
        selectedCategories += loadTextArray.get(selectedItems.keyAt(i)).toString() + ",";
      }
    }

    long finalCheckedItems[] = new long[rCheckedItems.size()];

    for (int x = 0; x < rCheckedItems.size(); x++) {
      finalCheckedItems[x] = Long.parseLong(rCheckedItems.get(x).toString());
    }

    Bundle bundle = new Bundle();
    selectedCategories = selectedCategories.trim();
    if (selectedCategories.endsWith(",")) {
      selectedCategories = selectedCategories.substring(0, selectedCategories.length() - 1);
    }

    bundle.putString("selectedCategories", selectedCategories);
    bundle.putLongArray("checkedItems", finalCheckedItems);
    Intent mIntent = new Intent();
    mIntent.putExtras(bundle);
    setResult(RESULT_OK, mIntent);
    finish();
  }
Esempio n. 3
0
 @Override
 protected void configureMenu11(Menu menu, int count, AbsListView lv) {
   super.configureMenu11(menu, count, lv);
   switch (lv.getId()) {
     case R.id.list:
       SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
       boolean hasForeignExchangeTransfer = false, hasPlan = false;
       for (int i = 0; i < checkedItemPositions.size(); i++) {
         if (checkedItemPositions.valueAt(i)
             && isForeignExchangeTransfer(checkedItemPositions.keyAt(i))) {
           hasForeignExchangeTransfer = true;
           break;
         }
       }
       for (int i = 0; i < checkedItemPositions.size(); i++) {
         if (checkedItemPositions.valueAt(i) && isPlan(checkedItemPositions.keyAt(i))) {
           hasPlan = true;
           break;
         }
       }
       configureMenuInternal(menu, count, hasForeignExchangeTransfer, hasPlan);
       break;
     case R.id.calendar_gridview:
       requirePlanMonthFragment().configureMenu11(menu, count, lv);
   }
 }
Esempio n. 4
0
  @Override
  public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
    // TODO Auto-generated method stub
    switch (item.getItemId()) {
      case R.id.show:
        SparseBooleanArray checked = content.getCheckedItemPositions();
        ArrayList<Integer> positions = new ArrayList<Integer>();
        for (int i = 0; i < checked.size(); i++) {
          if (checked.valueAt(i)) {
            positions.add(checked.keyAt(i));
          }
        }
        int[] arr = new int[positions.size()];
        int[] arr1 = new int[positions.size()];
        int k = 0;
        for (int position : positions) {
          arr[k] = mySQL.getID(position);
          arr1[k] = position;
          k++;
        }
        for (int j = 0; j < arr.length; j++) {

          mySQL.DeleteEntry(values[arr1[j]], arr[j]);
        }
        onCreate(new Bundle());
        mode.finish();
        return true;
    }
    return false;
  }
Esempio n. 5
0
  /**
   * Este método se llama al pulsar en el botón de borrar como se definió en el layout
   * res/layout/main.xml
   */
  public void deleteSelected(View view) {
    // Obtengo los elementos seleccionados de mi lista
    SparseBooleanArray seleccionados = miLista.getCheckedItemPositions();

    if (seleccionados == null || seleccionados.size() == 0) {
      // Si no había elementos seleccionados...
      Toast.makeText(this, "No hay elementos seleccionados", Toast.LENGTH_SHORT).show();
    } else {
      // si los había, miro sus valores

      // Esto es para ir creando un mensaje largo que mostraré al final
      StringBuilder resultado = new StringBuilder();
      resultado.append("Se eliminarán los siguientes elementos:\n");

      // Recorro my "array" de elementos seleccionados
      final int size = seleccionados.size();
      for (int i = 0; i < size; i++) {
        // Si valueAt(i) es true, es que estaba seleccionado
        if (seleccionados.valueAt(i)) {
          // en keyAt(i) obtengo su posición
          Cursor c = (Cursor) miLista.getItemAtPosition(seleccionados.keyAt(i));

          resultado.append("El elemento " + c.getString(2) + " estaba seleccionado\n");
        }
      }
      Toast.makeText(this, resultado.toString(), Toast.LENGTH_LONG).show();
    }
  }
 @Override
 public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
   menu.clear();
   MenuInflater inflater = mode.getMenuInflater();
   inflater.inflate(R.menu.newconversation_context, menu);
   SparseBooleanArray checkedItems = contactsView.getCheckedItemPositions();
   selectedContacts.clear();
   for (int i = 0; i < aggregatedContacts.size(); ++i) {
     if (checkedItems.get(i, false)) {
       selectedContacts.add(aggregatedContacts.get(i));
     }
   }
   if (selectedContacts.size() == 0) {
     menu.findItem(R.id.action_start_conversation).setVisible(false);
     menu.findItem(R.id.action_contact_details).setVisible(false);
     menu.findItem(R.id.action_invite).setVisible(false);
     menu.findItem(R.id.action_invite_to_existing).setVisible(false);
   } else if ((selectedContacts.size() == 1) && (!inviteIntent)) {
     menu.findItem(R.id.action_start_conversation).setVisible(true);
     menu.findItem(R.id.action_contact_details).setVisible(true);
     menu.findItem(R.id.action_invite).setVisible(false);
     menu.findItem(R.id.action_invite_to_existing).setVisible(true);
   } else if (!inviteIntent) {
     menu.findItem(R.id.action_start_conversation).setVisible(true);
     menu.findItem(R.id.action_contact_details).setVisible(false);
     menu.findItem(R.id.action_invite).setVisible(false);
     menu.findItem(R.id.action_invite_to_existing).setVisible(true);
   } else {
     menu.findItem(R.id.action_invite).setVisible(true);
     menu.findItem(R.id.action_start_conversation).setVisible(false);
     menu.findItem(R.id.action_contact_details).setVisible(false);
     menu.findItem(R.id.action_invite_to_existing).setVisible(false);
   }
   return true;
 }
Esempio n. 7
0
 private void deleteSelected() {
   ListView list = getListView();
   SparseBooleanArray checked = list.getCheckedItemPositions();
   ArrayList<String> deleted = new ArrayList<String>();
   for (int i = 0, lim = list.getAdapter().getCount(); i < lim; ++i)
     if (checked.get(i)) deleted.add((String) mAdapter.getItem(i));
   for (String s : deleted) mAdapter.remove(s);
   mAdapter.notifyDataSetChanged();
   mMode.finish();
 }
 private int qtdeItensMarcados() {
   SparseBooleanArray checked = mListView.getCheckedItemPositions();
   int checkedCount = 0;
   for (int i = 0; i < checked.size(); i++) {
     if (checked.valueAt(i)) {
       checkedCount++;
     }
   }
   return checkedCount;
 }
 public List<Host> getSelectedHosts() {
   SparseBooleanArray checked = hostList.getCheckedItemPositions();
   List<Host> ret = new LinkedList<Host>();
   for (int i = 0; i < hostList.getCount(); i++) {
     if (checked.get(i)) ret.add((Host) hostList.getItemAtPosition(i));
   }
   System.out.println("Selection:");
   System.out.println(ret);
   return ret;
 }
 // onStop() --> onDestroyView() --> onDestroy() --> onDetach() --> fragment is destroyed
 // The system calls onPause() as the first indication that the user is leaving the fragment
 // (though it does not always mean the fragment is being destroyed). This is usually where you
 // should commit any changes that should be persisted beyond the current user session (because
 // the user might not come back).
 @Override
 public void onPause() {
   if (isTestOutput) {
     System.out.println("onPause activated. sync called");
   }
   if (mListener != null) {
     // use checkedItemPositions array to update selected items in Main Activity
     mListener.syncSelectedTeams(fourthFragListView.getCheckedItemPositions());
   }
   super.onPause();
 }
Esempio n. 11
0
  @Override
  public void onClick(View v) {
    Log.d("mine", "onClick");

    switch (v.getId()) {
      case R.id.newExerciseOK:

        // get the data newExerciseName
        String name = etName.getText().toString();
        Exercise exercise = new Exercise();
        exercise.setExerciseName(name);

        // TODO: for now take only one selection, future = multiple
        SparseBooleanArray checked = mTypeListView.getCheckedItemPositions();
        ArrayList<String> selectedItems = new ArrayList<String>();
        for (int i = 0; i < checked.size(); i++) {
          // Item position in adapter
          int position = checked.keyAt(i);
          // Add sport if it is checked i.e.) == TRUE!
          if (checked.valueAt(i)) selectedItems.add(mTypeArrayAdapter.getItem(position));
        }

        String[] outputStrArr = new String[selectedItems.size()];

        for (int i = 0; i < selectedItems.size(); i++) {
          outputStrArr[i] = selectedItems.get(i);
          Log.d("mine", outputStrArr[i]);
          String type = outputStrArr[i];
          exercise.setExerciseType(type);
        }

        // validate entry

        // create Exercise Object

        // Toast.makeText(this.getActivity(),"hi",Toast.LENGTH_LONG).show();

        // return object
        mListener.onDialogPositiveClick(exercise);
        break;

      case R.id.newExerciseCancel:
        mListener.onDialogNegativeClick();
        this.dismiss();
        break;
        //            case R.id.button_three:
        //                // i'm lazy, do nothing
        //                break;
    }

    this.dismiss();
  }
 private List<ParseUser> getSelectedPlayers() {
   final List<ParseUser> selectedPlayers = new ArrayList<ParseUser>();
   final ListView playerListView = (ListView) findViewById(R.id.gamePlayersListView);
   final SparseBooleanArray checkedPlayers = playerListView.getCheckedItemPositions();
   if (checkedPlayers != null) {
     for (int i = 0; i < checkedPlayers.size(); i++) {
       if (checkedPlayers.valueAt(i)) { // was getting an invalid index 0 error, so check here
         selectedPlayers.add(playerList.get(checkedPlayers.keyAt(i)));
       }
     }
   }
   return selectedPlayers;
 }
  public int getCheckedItemCount() {
    ListView listView = mListView;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      return listView.getCheckedItemCount();
    }

    SparseBooleanArray checkedItems = listView.getCheckedItemPositions();
    int count = 0;
    for (int i = 0, size = checkedItems.size(); i < size; ++i) {
      if (checkedItems.valueAt(i)) {
        count++;
      }
    }
    return count;
  }
    @Override
    public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) {
      // We switch on the menu item's id, so we know which is clicked
      switch (menuItem.getItemId()) {

          // Our item with the menu_remove ID is used to remove the item(s) from the list.
          // Here we retrieve which positions are currently checked, then iterate through the
          // list and remove the checked items. Once finished we notify the adapter to update
          // the ListView contents and finish the action mode.
        case R.id.menu_remove:
          // Retrieve which positions are currently checked
          final ListView listView = getListView();
          SparseBooleanArray checkedPositions = listView.getCheckedItemPositions();

          // Check to see if there are any checked items
          if (checkedPositions.size() == 0) {
            return false;
          }

          // Iterate through the items and remove any which are checked
          final Iterator<String> iterator = mItems.iterator();
          int i = 0;
          while (iterator.hasNext()) {
            // Call next() so that the iterator index moves
            iterator.next();

            // Remove the item if it is checked (and increment position)
            if (checkedPositions.get(i++)) {
              iterator.remove();
            }
          }

          // Clear the ListView's checked items
          listView.clearChoices();

          // Finally, notify the adapter so that it updates the ListView
          ((BaseAdapter) getListAdapter()).notifyDataSetChanged();

          // As we're removing all of checked items, we'll close the action mode
          actionMode.finish();

          // We return true to signify that we have handled the action item click
          return true;
      }

      return false;
    }
Esempio n. 15
0
  @Override
  public void onClick(View v) {
    Log.d(TAG, "onclick " + (v == action_fab) + ", " + searchMode);
    if (v == search_fab) {
      if (searchMode == Var.SEARCH_NONE) toggleSearch(Var.SEARCH_OPTIONS);
      else if (searchMode == Var.SEARCH_OPTIONS) toggleSearch(Var.SEARCH_NONE);
    }

    if (v == action_fab) {
      if (searchMode == Var.SEARCH_YT_CHANNEL) {
        SparseBooleanArray checked = search_lv.getCheckedItemPositions();
        for (int i = 0; i < checked.size(); i++) {
          if (checked.valueAt(i) == true) {
            YoutubeFeed youtubeFeed = (YoutubeFeed) search_lv.getItemAtPosition(checked.keyAt(i));
            youtubeFeed.setChannelHandle(searchChannel.getFeedId());
            editUser.getMediaFeed().add(youtubeFeed);
          }
        }

        feedAdapter.notifyDataSetChanged();
        clearSearchOptions();

        toggleSearch(Var.SEARCH_NONE);
      } else if (searchMode == Var.SEARCH_NONE) {

        editUser.setName(userName_edt.getText().toString().trim());
        editUser.setNotification(notification_sw.isChecked());
        editUser.setThumbnail((String) userPicture_sp.getSelectedItem());

        UserORM.saveUser(this, editUser);

        finish();
      }
    }
    if (v == youtube_ll) toggleSearch(Var.SEARCH_YOUTUBE);
    if (v == twitter_ll) toggleSearch(Var.SEARCH_TWITTER);
    if (v == search_v) toggleSearch(Var.SEARCH_NONE);
    if (v == searchTwitterLogin_tv) {
      twitter.resetAccessToken();
      if (!twitter.hasAccessToken()) twitter.authorize();
      // Hide the signin
      searchTwitter_v.setVisibility(View.GONE);
      searchDiv_v.setVisibility(View.GONE);
    }
    if (v == clearSearch_iv) search_edt.getText().clear();
  }
  private void confirmMultiAction() {
    SparseBooleanArray booleanArray = mMsgListView.getCheckedItemPositions();
    int size = booleanArray.size();

    mSelectedLockedUris.clear();

    if (size > 0) {
      for (int j = 0; j < size; j++) {
        int position = booleanArray.keyAt(j);
        if (!mMsgListView.isItemChecked(position)) {
          continue;
        }
        Cursor c = (Cursor) mMsgListAdapter.getItem(position);
        if (c == null) {
          return;
        }
        mSelectedCursors.add(c);
        if (mManageMode == MessageUtils.FORWARD_MODE) {
          String type = c.getString(COLUMN_MSG_TYPE);
          long msgId = c.getLong(COLUMN_ID);
          mMessageItems.add(mMsgListAdapter.getCachedMessageItem(type, msgId, c));
        } else if (mManageMode == MessageUtils.SIM_MESSAGE_MODE) {
          mSelectedUris.add(getUriStrByCursor(c));
        } else if (mManageMode == MessageUtils.BATCH_DELETE_MODE) {
          long msgId = c.getLong(COLUMN_ID);
          Uri uri =
              c.getString(COLUMN_MSG_TYPE).equals("sms")
                  ? ContentUris.withAppendedId(Sms.CONTENT_URI, msgId)
                  : ContentUris.withAppendedId(Mms.CONTENT_URI, msgId);
          if (c.getInt(COLUMN_SMS_LOCKED) == MESSAGE_LOCKED) {
            mSelectedLockedUris.add(uri.toString());
          }
          mSelectedUris.add(uri.toString());
        }
      }
    }

    if (mManageMode == MessageUtils.FORWARD_MODE) {
      forwardSmsConversation();
    } else if (mManageMode == MessageUtils.SIM_MESSAGE_MODE
        || mManageMode == MessageUtils.BATCH_DELETE_MODE) {
      MultiMessagesListener l = new MultiMessagesListener();
      confirmDeleteDialog(l);
    }
  }
  public void onClickSaveAndFinish() {
    String temp;
    int counter = 0;
    String[] choosenItems = new String[100];
    SparseBooleanArray checked = lv.getCheckedItemPositions();

    for (int i = 0; i < lv.getAdapter().getCount(); i++) {
      if (checked.get(i)) {
        Log.i("", "This was checked: " + workouts[i]);
        choosenItems[counter] = workouts[i];
        counter++;
      }
    }
    workout.printWorkOut();

    Intent intent = new Intent(ClickableCreateWorkOutList.this, NameWorkout.class);
    intent.putExtra("myExtra", workout);
    startActivity(intent);
  }
Esempio n. 18
0
  @Override
  public void onClick(View v) {
    // TODO Auto-generated method stub
    switch (v.getId()) {
      case (R.id.selectall):
        for (int i = 0; i < listContacts.getCount(); i++) {
          listContacts.setItemChecked(i, true);
        }
        break;
      case (R.id.deselectall):
        for (int i = 0; i < listContacts.getCount(); i++) {
          listContacts.setItemChecked(i, false);
        }
        break;

      case (R.id.syncme):
        SparseBooleanArray checked = listContacts.getCheckedItemPositions();
        for (int i = 0; i < checked.size(); i++) {
          int key = checked.keyAt(i);
          boolean value = checked.get(key);
          if (value) {
            if (selectedItemList.contains(listContacts.getItemAtPosition(key))) {
              Log.v(TAG, listContacts.getItemAtPosition(key).toString() + " is a duplicate!!!!");
            }
            selectedItemList.add((String) listContacts.getItemAtPosition(key));
          } else {

          }
        }
        // (TAG, "added " + selectedItemList.size() + " contacts to sync queue");
        CCC =
            new CreateContactsContent(
                getActivity().getApplicationContext(),
                getActivity().getContentResolver(),
                selectedItemList);
        if ((CCC != null) && (CCC.getStatus() != AsyncTask.Status.RUNNING)) {
          CCC.execute();
        }
    }
  }
Esempio n. 19
0
 public void doClick(View view) {
   int count = lv.getCount();
   SparseBooleanArray viewItems = lv.getCheckedItemPositions();
   for (int i = 0; i < count; i++) {
     if (viewItems.get(i)) {
       // CursorWrapper cw = (CursorWrapper) lv.getItemAtPosition(i);
       cursor.moveToPosition(i);
       long id = cursor.getLong(idCol);
       String name = cursor.getString(nameCol);
       int timesContacted = cursor.getInt(timesContactedCol);
       Log.v(
           TAG,
           name
               + " is checked. Times contacted = "
               + timesContacted
               + ". Position = "
               + i
               + ". Id = "
               + id);
     }
   }
 }
Esempio n. 20
0
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {
     case R.id.select_all:
       for (int i = 0; i < mListView.getCount(); i++) {
         mListView.setItemChecked(i, true);
       }
       return true;
     case R.id.unselect_all:
       for (int i = 0; i < mListView.getCount(); i++) {
         mListView.setItemChecked(i, false);
       }
       return true;
     case R.id.action_done:
       SparseBooleanArray array = mListView.getCheckedItemPositions();
       StringBuilder stringBuilder = new StringBuilder();
       StringBuilder namesBuilder = new StringBuilder();
       for (int i = 0; i < mListView.getCount(); i++) {
         if (array.get(i)) {
           String out = (String) mListView.getAdapter().getItem(i);
           String lines[] = out.split("\\r?\\n");
           stringBuilder.append(lines[1]).append(",");
           namesBuilder.append(lines[0]).append(",");
         }
       }
       Intent intent = new Intent();
       if (stringBuilder.length() != 0) {
         intent.putExtra("selected_contacts", stringBuilder.toString());
         intent.putExtra(
             "selected_names",
             getFormattedContacts(namesBuilder.toString(), stringBuilder.toString()));
       }
       intent.putExtra("temporary", true);
       setResult(AppGlobals.RESULT_OK, intent);
       finish();
       return true;
   }
   return super.onOptionsItemSelected(item);
 }
  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    fourthFragListView = (ListView) view.findViewById(R.id.fourth_frag_listview);

    // create a dummy team list - in the production app, this list would be provided by the
    // webserver
    teamList = new ArrayList<>();
    String teamInfo;
    for (int i = 1; i < (numTeams + 1); i++) {
      teamInfo = "Team " + i + "  --  Teamlead" + i;
      teamList.add(teamInfo);
    }

    // instantiate adapter with data list
    teamAdapter = new TeamAdapter(getContext(), teamList);

    // attach adapter to listview
    fourthFragListView.setAdapter(teamAdapter);

    fourthFragListView.setOnItemClickListener(
        new android.widget.AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // handle response in separate method
            clickResponse(position);
          }
        });

    // bring listview's selected-items list up to date with preselected teams so teams
    // whose appointments are all selected show the proper highlighting on startup
    SparseBooleanArray startupSelectedList = mListener.getSBAForSelectedTeams();
    SparseBooleanArray checkedItemPositions = fourthFragListView.getCheckedItemPositions();
    for (int i = 0; i < startupSelectedList.size(); i++) {
      checkedItemPositions.append(
          (startupSelectedList.keyAt(i) - 1), // team i is in listview item i-1
          startupSelectedList.valueAt(i));
    }
  } // end onViewCreated
  private void remover() {
    final List<Hotel> hoteisExcluidos = new ArrayList<Hotel>();
    SparseBooleanArray checked = mListView.getCheckedItemPositions();
    for (int i = checked.size() - 1; i >= 0; i--) {
      if (checked.valueAt(i)) {
        int position = checked.keyAt(i);
        Cursor cursor = (Cursor) mListView.getItemAtPosition(position);
        Hotel hotel = mRepositorio.hotelFromCursor(cursor);
        hoteisExcluidos.add(hotel);
        mRepositorio.excluir(hotel);
      }
    }
    Activity activity = getActivity();
    if (activity instanceof AoExcluirHoteis) {
      AoExcluirHoteis aoExcluirHoteis = (AoExcluirHoteis) activity;
      aoExcluirHoteis.exclusaoCompleta(hoteisExcluidos);
    }

    Snackbar.make(
            mListView,
            getString(R.string.mensagem_excluir, hoteisExcluidos.size()),
            Snackbar.LENGTH_LONG)
        .setAction(
            R.string.desfazer,
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                for (Hotel hotel : hoteisExcluidos) {
                  hotel.status = Hotel.Status.ATUALIZAR;
                  mRepositorio.inserirLocal(hotel, getActivity().getContentResolver());
                }
                limparBusca();
              }
            })
        .show();
  }
 // action to perform when listview item is selected
 void clickResponse(int position) {
   //        long[] idArray = listview.getCheckedItemIds(); //can't use: API is too recent for min
   // version in specs
   //        int idCount = listview.getCheckedItemCount(); //can't use: API is too recent for min
   // version in specs
   SparseBooleanArray idBArray = fourthFragListView.getCheckedItemPositions();
   if (isTestOutput) {
     System.out.println(idBArray.toString());
   }
   String outputString = "";
   for (int i = 0; i < idBArray.size(); i++) {
     if (isTestOutput) {
       System.out.println(
           "i = " + i + ", key = " + idBArray.keyAt(i) + ", value = " + idBArray.valueAt(i));
     }
     if (idBArray.valueAt(i)) { // value is true = item is selected
       if (i > 0) outputString += ", ";
       if (isTestOutput) {
         System.out.println("adapter item at key: " + teamAdapter.getItem(idBArray.keyAt(i)));
       }
       outputString += teamAdapter.getItem(idBArray.keyAt(i));
     }
   }
 } // end clickResponse
Esempio n. 24
0
  public void guardarComidas(View view) {
    // Obtengo los elementos seleccionados de mi lista
    SparseBooleanArray seleccionados = miLista.getCheckedItemPositions();

    if (seleccionados == null || seleccionados.size() == 0) {
      // Si no había elementos seleccionados...
      Toast.makeText(this, "No hay elementos seleccionados", Toast.LENGTH_SHORT).show();
    } else {
      // si los había, miro sus valores

      // Esto es para ir creando un mensaje largo que mostraré al final
      // StringBuilder resultado=new StringBuilder();

      // Recorro my "array" de elementos seleccionados
      final int size = seleccionados.size();
      String codigo = null;
      for (int i = 0; i < size; i++) {
        // Si valueAt(i) es true, es que estaba seleccionado
        if (seleccionados.valueAt(i)) {
          // en keyAt(i) obtengo su posición
          Cursor c = (Cursor) miLista.getItemAtPosition(seleccionados.keyAt(i));

          // resultado.append("El elemento "+c.getString(2)+" estaba seleccionado\n");

          codigo = null;
          Bundle extras = getIntent().getExtras();
          if (extras != null) {
            codigo = extras.getString("codigo");
          }

          ContentValues values = new ContentValues();

          values.put(DetalleRutinaAlimentoProvider.ID_RUTINA_ALIMENTO, codigo);
          values.put(DetalleRutinaAlimentoProvider.ID_ALIMENTO, c.getString(0)); // 5
          values.put(DetalleRutinaAlimentoProvider.CANTIDAD_INGERIDA_G, "1");
          values.put(DetalleRutinaAlimentoProvider.CALORIAS_KCAL, c.getString(9));
          values.put(DetalleRutinaAlimentoProvider.GRASAS_G, c.getString(10));
          values.put(DetalleRutinaAlimentoProvider.PROTEINAS_G, c.getString(11));
          values.put(DetalleRutinaAlimentoProvider.CARBOHIDRATOS_G, c.getString(12));

          Uri uriNuew =
              getContentResolver().insert(DetalleRutinaAlimentoProvider.CONTENT_URI, values);

          // IO implemento
          Cursor c2 = managedQuery(uriNuew, null, null, null, null);
        }
      }

      String regimen = null;
      String fecha = null;
      Bundle extras = getIntent().getExtras();
      if (extras != null) {
        regimen = extras.getString("regimen");
        codigo = extras.getString("codigo");
        fecha = extras.getString("fecha");
      }

      // updateRutina(getDatePhone());
      Intent i = new Intent(this, ListaComidasSeleccionadasHistorial.class);
      i.putExtra("regimen", regimen);
      i.putExtra("codigo", codigo);
      i.putExtra("fecha", fecha);
      Log.d("my tag2", "feha LCH: " + fecha);
      startActivity(i);
    }
  }