title: How to take the value of the checked row in list view, and get the prefered text field?
body: <p>I fulfill the <strong>AlertDIalog</strong> and <strong>ListView</strong> with two values <code>Name</code> and <code>id</code>, and I cannot find conclusion оr the right way, when i checked some CheckBoxes, i need the value of the Checked/Selected rows of (id's text) to save.  </p>
  
  <pre><code>    @OnClick(R.id.group_delete)    
      void deleteGroup() {
  
      AlertDialog.Builder dialog4 = new AlertDialog.Builder(PreviewActivity.this);
  
      LayoutInflater inflater2 = getLayoutInflater();
      View convertView2 = (View) inflater2.inflate(R.layout.alert_dialog_delete_group, null);
      dialog4.setView(convertView2);
  
      ListView listView2 = (ListView) convertView2.findViewById(R.id.listViewGroup);
  
      final List&lt;Item&gt; groupList = this.getGroup();
  
      CustomAdapter listAdapter2 = new CustomAdapter(getBaseContext(), groupList);
  
      // listAdapter2.notifyDataSetChanged();
  
      convertView2.setTag(dialog4);
  
   //   SparseBooleanArray sp = listView2.getCheckedItemPositions();
  
      listView2.setOnItemClickListener((AdapterView&lt;?&gt; adapterView, View view, int position, long l) -&gt; {
          // Get user selected item.
          Object itemObject = adapterView.getAdapter();
  
          Item itemDto = (Item) itemObject;
  
          CheckBox itemCheckbox = (CheckBox) convertView2.findViewById(R.id.checkMark5);
          listAdapter2.setCheckedItem(position);
      });
  
  
      ImageView delete = (ImageView) convertView2.findViewById(R.id.del_group);
      delete.setOnClickListener((View view) -&gt; {
  
          CheckBox itemCheckbox = (CheckBox) convertView2.findViewById(R.id.checkMark5);
  
          Iterator&lt;String&gt; it = listAdapter2.getCheckedItems().values().iterator();
          for (int i=0;i&lt;listAdapter2.getCheckedItems().size();i++){
              //Do whatever
         //                String result = "";
  
         //                ArrayList&lt;String&gt; resultList = new ArrayList&lt;String&gt;();
         //                for (int y = 0; y &lt; resultList.size(); y++) {
         //                        result += String.valueOf(resultList.get(i)) + "\n";
         //                    }
         //                if (result.matches("")) {
         ////
         //                        Toast.makeText(getApplicationContext(),"Please select some thing from list to show",Toast.LENGTH_LONG).show();
      //                    }
  
      //                else {
                           Toast.makeText(getApplicationContext(),result,Toast.LENGTH_LONG).show();
      //                    }
  
  
                  listAdapter2.getItem(Integer.parseInt(it.next()));
              }
  
          //   List&lt;Item&gt; resultList = listAdapter2.getCheckedItems();
  
      //                    for (int i = 0; i &lt; resultList.size(); i++) {
      //                        result += String.valueOf(resultList.get(i)) + "\n";
      //                    }
  
      //                    listAdapter2.getCheckedItemPositions().toString();
      //
      //                    if (result.matches("")) {
      //
      //                        Toast.makeText(getApplicationContext(),"Please select some thing from list to show",Toast.LENGTH_LONG).show();
      //                    }
      //                    else {
                     Toast.makeText(getApplicationContext(),result,Toast.LENGTH_LONG).show();
      //                    }
  
  
          //   shared.setSharedPreferencesString(Constants.ID, size2);
  
  
          listAdapter2.notifyDataSetChanged();
      });
  
      listView2.setAdapter(listAdapter2);
      listView2.setTag(dialog4);
  
      AlertDialog alert4 = dialog4.create();
  
      alert4.show();
  
      alert4.getWindow().
  
              setBackgroundDrawable(new ColorDrawable(android.graphics.Color.argb(0, 100, 100, 100)));
  }
  
  public List&lt;Company&gt; getCompanies() {
      return mCompanies;
  }
  
  private List&lt;Item&gt; getGroup() {
  
  
      ArrayList&lt;String&gt; groups = new ArrayList&lt;String&gt;();
  
      ArrayList&lt;String&gt; groups2 = new ArrayList&lt;&gt;();
  
      for (Group group2 : mRepository.getCompanies().get(posit).getGroups()) {
  
  
          groups2.add(group2.getId());
      }
  
      for (Group group1 : mRepository.getCompanies().get(posit).getGroups()) {
  
          groups.add(group1.getName());
  
  
      }
  
  
      List&lt;Item&gt; ret = new ArrayList&lt;Item&gt;();
  
      int length = groups.size();
  
      for (int i = 0; i &lt; length; i++) {
  
  
          String itemText2 = groups.get(i);
          String itemText3 = groups2.get(i);
  
  
          Item dto = new Item();
          dto.setChecked(false);
          dto.setIdText(itemText3);
          dto.setItemText(itemText2);
  
  
  
          ret.add(dto);
  
      }
      return ret;
  
  }
  </code></pre>
  
  <p><strong>Item Class:</strong></p>
  
  <pre><code>public class Item { 
  
  private boolean checked ;
  private String itemText = "";
  private String IdText = "";
  private String IdText2 = "";
  
  public String getIdText2() {
      return IdText2;
  }
  
  public void setIdText2(String idText2) {
      IdText2 = idText2;
  }
  
  public String getIdText() {
      return IdText;
  }
  
  public void setIdText(String idText) {
      IdText = idText;
  }
  
  
  
  public boolean isChecked() {
      return checked;
  }
  
  public void setChecked(boolean checked) {
      this.checked = checked;
  }
  
  public String getItemText() {
      return itemText;
  }
  
  public void setItemText(String itemText) {
      this.itemText = itemText;
  }}
  </code></pre>
  
  <p><strong>CustomAdapter :</strong></p>
  
  <pre><code>public class CustomAdapter extends BaseAdapter {
  
  private List&lt;Item&gt; ItemList ;
  
  public HashMap&lt;String, String&gt; checked = new HashMap&lt;String, String&gt;();
  
  private Context ctx;
  
  public CustomAdapter(Context ctx, List&lt;Item&gt; ItemList) {
      this.ctx = ctx;
      this.ItemList = ItemList;
  }
  
  public void setCheckedItem(int item) {
  
      if (checked.containsKey(String.valueOf(item))) {
          checked.remove(String.valueOf(item));
      } else {
          checked.put(String.valueOf(item), String.valueOf(item));
      }
  }
  
  public HashMap&lt;String, String&gt; getCheckedItems() {
      return checked;
  }
  
  
  @Override
  public int getCount() {
      return ItemList.size();
  }
  
  @Override
  public Object getItem(int position) {
      return ItemList.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      return 0;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup viewGroup) {
  
      ItemViewHolder viewHolder = null;
  
      if (convertView != null) {
          viewHolder = (ItemViewHolder) convertView.getTag();
      } else {
  
          convertView = View.inflate(ctx, R.layout.custom, null);
  
          CheckBox checkbox = (CheckBox) convertView.findViewById(R.id.checkMark5);
  
          TextView listItemText = (TextView) convertView.findViewById(R.id.item_unit_id5);
  
          TextView tetx = (TextView) convertView.findViewById(R.id.tekst5);
  
          TextView textId = (TextView) convertView.findViewById(R.id.item_number5);
  
          viewHolder = new ItemViewHolder(convertView);
  
          viewHolder.setItemCheckbox(checkbox);
          viewHolder.setItemTextView(listItemText);
          viewHolder.setIdTextView(textId);
          viewHolder.setIdTextView2(tetx);
  
          convertView.setTag(viewHolder);
  
      }
  
      Item items = ItemList.get(position);
      viewHolder.getItemCheckbox().setChecked(items.isChecked());
      viewHolder.getItemTextView().setText(items.getItemText());
      viewHolder.getIdTextView().setText(items.getIdText());
      viewHolder.getIdTextView2().setText(items.getIdText2());
  
      return convertView;
  }}
  </code></pre>
  
  <p><strong>ViewHolder :</strong></p>
  
  <pre><code>public class ItemViewHolder extends RecyclerView.ViewHolder {
  
  private CheckBox itemCheckbox;
  private TextView IdTextView;
  private TextView itemTextView;
  private TextView IdTextView2;
  
  public TextView getIdTextView2() {
      return IdTextView2;
  }
  
  public void setIdTextView2(TextView idTextView2) {
      IdTextView2 = idTextView2;
  }
  
  public ItemViewHolder(View itemView) {
      super(itemView);
  }
  
  public TextView getIdTextView() {
      return IdTextView;
  }
  
  public void setIdTextView(TextView idTextView) {
      IdTextView = idTextView;
  }
  
  public CheckBox getItemCheckbox() {
      return itemCheckbox;
  }
  
  public void setItemCheckbox(CheckBox itemCheckbox) {
      this.itemCheckbox = itemCheckbox;
  }
  
  public TextView getItemTextView() {
      return itemTextView;
  }
  
  public void setItemTextView(TextView itemTextView) {
      this.itemTextView = itemTextView;
  }  }
  </code></pre>