Sorting of files according to file or folder
<p>i have an array of names which have multiple files and folders...now i want to sort the names according to files and folders.all folders first and then all files should display.i have the variable to check whether on particular index of array their is file or folder.but unable to think the logic..
i am attaching some of my codes.</p>

<p>////////////////////////////////
case 0://Sort By Name
                        {</p>

<pre><code>                        if(m_sortType == SORT_BY_NAME &amp;&amp; temp==false)
                        {
                            m_sortType = SORT_BY_NAME;
                            m_sortOrder=SORT_ORDER_DESCENDING;
                            temp= true;
                            //Log.d("SORTING", "SORT - NAME - DES");
                        }
                        else
                        {
                            m_sortType = SORT_BY_NAME;
                            m_sortOrder=SORT_ORDER_ASCENDING;
                            temp=false;
                            //Log.d("SORTING", "SORT - NAME - AES");
                        }

                        //Log.d("SORTING", "Data bfore sort");
                        for (int k=0; k&lt;m_adapter.m_env.m_count; k++)
                            //Log.d("SORTING DATA", k + ": " + m_adapter.m_env.m_fs.get(m_SortArray[k]).m_name);

                        m_adapter.sortListing(m_sortType,m_sortOrder);

                        //Log.d("SORTING", "Data after sort");
                        for (int k=0; k&lt;m_adapter.m_env.m_count; k++)
                            //Log.d("SORTING DATA", k + ": " + m_adapter.m_env.m_fs.get(m_SortArray[k]).m_name);

                        //Refresh();
                        break;
                    }
</code></pre>

<p>////////////////
private  void sortListing(int sortType, int sortOrder)
        {
            m_sortType = sortType;
            m_sortOrder = sortOrder;
            Arrays.sort( m_SortArray , new Comparator() {</p>

<pre><code>            public int compare(Integer a1, Integer a2)
            {

                if(m_sortType == SORT_BY_NAME)
                {
                    String s1 = null,s2 = null;
                    FileFolderEnum t2 = null;
                    FileFolderEnum t1 = null;
                    int i;
                    if(m_sortOrder==SORT_ORDER_ASCENDING)
                    {
                        s1 = m_env.m_fs.get(a1).m_name;
                        s2 = m_env.m_fs.get(a2).m_name;
                        t1 = m_env.m_fs.get(a1).m_type;
                        t2 = m_env.m_fs.get(a2).m_type;
                    }
                    else if(m_sortOrder==SORT_ORDER_DESCENDING)
                    {
                        s1 = m_env.m_fs.get(a2).m_name;
                        s2 = m_env.m_fs.get(a1).m_name;
                        t1 = m_env.m_fs.get(a2).m_type;
                        t2 = m_env.m_fs.get(a1).m_type;
                    }
                    //Log.d("SORTING COMPARE", "(" + Integer.toString(a1)+") s1: " + s1);
                    //Log.d("SORTING COMPARE", "(" + Integer.toString(a2)+") s2: " + s2);
                    if((t1.equals(CFileFolder.FileFolderEnum.FFE_FOLDER)&amp;&amp;(t2.equals(CFileFolder.FileFolderEnum.FFE_FOLDER))))
                    {
                         i=s1.compareToIgnoreCase (s2);
                    }
                     i=s1.compareToIgnoreCase (s2);

                    //Log.d("SORTING COMPARE", "s1.compareTo(s2): " + Integer.toString(i));
                    return i;
                }
</code></pre>

<p>///////////////////</p>
