title: Sorting of objects works only on layout scrollling: Android
body: <p>I have a class as,</p>
  
  <pre><code>public class ACompanyForSearchResult {
  String companyName;;
  int likes;
  }
  </code></pre>
  
  <p>And a list of it:</p>
  
  <pre><code>ArrayList&lt;ACompanyForSearchResult&gt; List = new ArrayList&lt;ACompanyForSearchResult&gt;();
  </code></pre>
  
  <p>Here I am sorting it by name and number of likes as,</p>
  
  <pre><code>/*To get the sorted value by name*/
  private void sortName() {
   Collections.sort(List, new Comparator&lt;ACompanyForSearchResult&gt;() {
              @Override
              public int compare(ACompanyForSearchResult aCompanyForSearchResult, ACompanyForSearchResult t1) {
                  return (aCompanyForSearchResult.companyName).compareToIgnoreCase(t1.companyName);
              }
          });
      }
  }
  
  /*To get the sorted value by kudos* */
  private void sortLikes() {
          Collections.sort(List, new Comparator&lt;ACompanyForSearchResult&gt;() {
              @Override
              public int compare(ACompanyForSearchResult aCompanyForSearchResult, ACompanyForSearchResult t1) {
                  return (int) t1.likes - aCompanyForSearchResult.likes;
              }
          });
      }
  }
  </code></pre>
  
  <p>The data is being sorted as expected but the issue is that it gets sorted only when the layout is being scorlled. I tried searching on it but couldn't find anything relavant. I cannot understand why the sorting will only work when the layout is being scrolled.
  Can anyone please help?</p>