title: How to sort a listview in alphabetical order
body: <p>I've been following this tutorial <a href="http://code.tutsplus.com/tutorials/build-a-custom-launcher-on-android--cms-21358" rel="nofollow">here</a> on how to make my own Android launcher. I can currently display all the installed apps on my phone in a listview. How can I edit this code so that the list is in alphabetical order?</p>
  
  <pre><code>    protected void onCreate(Bundle savedInstanceState) {    
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_apps_list);
  
          loadApps();
          loadListView();
          addClickListener();
      }
  
  private PackageManager manager;
  private List&lt;AppDetail&gt; apps; 
  private void loadApps(){
      manager = getPackageManager();
      apps = new ArrayList&lt;AppDetail&gt;();
  
      Intent i = new Intent(Intent.ACTION_MAIN, null);
      i.addCategory(Intent.CATEGORY_LAUNCHER);
  
      List&lt;ResolveInfo&gt; availableActivities = manager.queryIntentActivities(i, 0);
      for(ResolveInfo ri:availableActivities){
          AppDetail app = new AppDetail();
          app.label = ri.loadLabel(manager);
          app.name = ri.activityInfo.packageName;
          app.icon = ri.activityInfo.loadIcon(manager);
          apps.add(app);
      }
  }
  
  private ListView list;    
  private void loadListView(){
      list = (ListView)findViewById(R.id.apps_list);
  
      ArrayAdapter&lt;AppDetail&gt; adapter = new ArrayAdapter&lt;AppDetail&gt;(this, 
              R.layout.list_item, 
              apps) {
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              if(convertView == null){
                  convertView = getLayoutInflater().inflate(R.layout.list_item, null);
              }
  
              ImageView appIcon = (ImageView)convertView.findViewById(R.id.item_app_icon);
              appIcon.setImageDrawable(apps.get(position).icon);
  
              TextView appLabel = (TextView)convertView.findViewById(R.id.item_app_label);
              appLabel.setText(apps.get(position).label);
  
              TextView appName = (TextView)convertView.findViewById(R.id.item_app_name);
              appName.setText(apps.get(position).name);
  
              return convertView;
          }
      };
  
      list.setAdapter(adapter);           
  }
  
  private void addClickListener(){        
      list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; av, View v, int pos,
                  long id) {
              Intent i = manager.getLaunchIntentForPackage(apps.get(pos).name.toString());
              AppsListActivity.this.startActivity(i);
          }
      });
  }
  </code></pre>