コード例 #1
0
      public void bind(final int position) {
        AppContainer item = mDataset.get(position);

        checkbox.setChecked(item.isChecked());
        title.setText(item.getFriendlyName());
        description.setText(item.getPackageName());

        itemView.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                AppContainer item = mDataset.get(position);
                if (checkbox.isChecked()) {
                  item.setChecked(false);
                  checkbox.setChecked(false);
                } else {
                  item.setChecked(true);
                  checkbox.setChecked(true);
                }

                mDataset.set(position, item);
                notifyItemChanged(position);
              }
            });
      }
コード例 #2
0
    public ArrayList<AppContainer> getSelectedItems() {
      ArrayList<AppContainer> selected = new ArrayList<>();
      for (int i = 0; i < mDataset.size(); i++) {
        AppContainer item = mDataset.get(i);
        if (item.isChecked()) {
          selected.add(item);
        }
      }

      if (selected.isEmpty()) {
        selected.add(new AppContainer(AppContainer.TYPE_NOTHING));
      }

      return selected;
    }