title: Sort order of selected items in ListView with CheckedTextView
body: <p>I successfully implemented an <code>AlertDialog</code> that shows a <code>custom-styled-row</code> of <code>CheckedTextViews</code>. The problem comes when selecting the items. At the end, the order is going to be established by their position in the <code>ListView</code>. If a user selects an item from the bottom of the list and then an item from the top, the answer given by the <code>Dialog's</code> <code>OnClickListener</code> will begin with the top one instead from the bottom one. Is there a way to sort these items by click?</p>
  
  <p>Here is my implementation to retrieve the items checked:</p>
  
  <pre><code>private void setCheckedItems(){
  
      SparseBooleanArray checkedItems = listView.getCheckedItemPositions();
      if (checkedItems != null) {
          for (int i = 0; i&lt;checkedItems.size(); i++) {
              if (checkedItems.valueAt(i)) {
                  mSelectedItems.add(tables[checkedItems.keyAt(i)]);
              }
          }
      }
  }
  </code></pre>
  
  <p>Note: I tried to avoid this problem by calling <code>OnItemClickListener</code> on my <code>ListView</code>, but the items that were in positions longer than the space of the screen began to be checked as well. So, at the end I used <code>listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);</code> instead of the click listener.</p>
  
  <p>Thank you very much.</p>