Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I finally figured it out! Thanks to a bigger project coming across a similar issue essentially forcing me to get this solved. Everything outside this sample is mostly the same as it was at the original post apart from some changed variable names. I'm not sure if this is the best way to do it, but it gets the job done at a very acceptable speed and I can actually understand how it works.</p> <pre><code>ArrayList&lt;HashMap&lt;String, String&gt;&gt; list = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;(); // Put separated item details in a HashMap for each item, // then insert it in sorted order to list. for(int n = 0; n &lt; arrayTitle.size(); n++) { HashMap&lt;String, String&gt; item = new HashMap&lt;String, String&gt;(); item.put("title", arrayTitle.get(n)); item.put("desc", arrayDesc.get(n)); try { int c, i = 0; do { // Compare new title with titles existing in list // from beginning to end or until title is found that it goes before. c = arrayTitle.get(n).compareTo(list.get(i).get("title")); i++; } while (c &gt; 0 &amp; i &lt; list.size()); i--; if(c &gt; 0) { // New item goes after all others currently in list. list.add(item); } else if (c &lt; 0) { // New item goes before an item already in list. list.add(i, item); } } catch (Exception e) { // If nothing in list to compare with, add first item. list.add(item); } } SimpleAdapter adapter = new SimpleAdapter(this, list, android.R.layout.simple_list_item_2, new String[] {"title", "desc"}, new int[]{android.R.id.text1, android.R.id.text2}); setListAdapter(adapter); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload