title: Get locale from language display name
body: <p>I am trying to set my Text-To-Speech language from its display name. The problem is that Text-to-Speech requires a Locale for setLanguage.How do I progress from display language to locale? I first set up my recycler list in this way:</p>
  
  <pre><code> public void getSystemLanguages() {
      systemLanguages = Resources.getSystem().getAssets().getLocales();
      for (int i = 1; i &lt; systemLanguages.length; i++) {
          String sL = systemLanguages[i];
          Locale loc = Locale.forLanguageTag(sL);
          String locDisplayResults = loc.getDisplayName();
          languagesList.add(new Languages(locDisplayResults));
          Collections.sort(languagesList, new Comparator&lt;Languages&gt;() {
              @Override
              public int compare(Languages languages1, Languages languages2) {
                  return languages1.getLocaleDisplay().compareTo(languages2.getLocaleDisplay());
              }
          });
          recyclerAdapter.notifyDataSetChanged();
      }
  }
  </code></pre>
  
  <p>I then have a recycler adapter which looks like this:</p>
  
  <pre><code>public void onClick(View view) {
                                              final Languages currentLanguages = languagesList.get(getAdapterPosition());
                                              Snackbar snackbar;
                                              snackbar = Snackbar.make(view, currentLanguages.getLocaleDisplay() + " selected", Snackbar.LENGTH_INDEFINITE)
                                                      .setAction("Next", new View.OnClickListener() {
                                                          @Override
                                                          public void onClick(View v) {
                                                              Intent intent = new Intent(v.getContext(), MainActivity.class);
                                                              chosenLanguage = localeDisplay.getText().toString();
                                                              intent.putExtra("language_key", chosenLanguage);
                                                              v.getContext().startActivity(intent);
                                                          }
                                                      });
  
                                              View snackBarView = snackbar.getView();
                                              snackBarView.setBackgroundColor(grey_blue);
                                              snackbar.show();
                                          }
  </code></pre>
  
  <p>I think it should be fairly easy to achieve although I have spent over a week on this with no success. Any help would be fantastic!</p>
  
  <p>Edit: I'm adding my Language class in case anyone can help me with Andreas' solution:</p>
  
  <pre><code>    public class Language {
  
  public String localeDisplay;
  
  public Language (String localeDisplay) {
      this.localeDisplay = localeDisplay;
  }
  
  public String getLocaleDisplay() {
      return localeDisplay;
  </code></pre>
  
  <p>}
   }
  Cheers!</p>
  
  <p>Here is what I've tried:</p>
  
  <pre><code>public class Language {
  
  public String localeDisplay;
  public Locale mLocale;
  
  
  public Language(String localeDisplay) {
      this.localeDisplay = localeDisplay;
  }
  
  public Language(Locale mLocale){
      this.mLocale = mLocale;
  }
  
  public String getLocaleDisplay() {
      return localeDisplay;
  }
  
  public void setmLocale(Locale mLocale) {
      this.mLocale = mLocale;
  }
  
  public Locale getmLocale() {
      return mLocale;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>New edit: here is the correct version:</p>
  
  <pre><code>public class Language implements Comparable &lt;Language&gt; {
  
  public String localeDisplay;
  public Locale mLocale;
  
  public Language(Locale mLocale, String localeDisplay) {
      if (mLocale != null)
          this.mLocale = mLocale;
      if (localeDisplay != null)
          this.localeDisplay = localeDisplay;
  }
  
  public Locale getmLocale(){
      return mLocale;
  }
  
  public String getLocaleDisplay(){
      return localeDisplay;
  }
  
  public int compareTo(Language l){
      return localeDisplay.compareTo(l.localeDisplay);
  }
  </code></pre>
  
  <p>}</p>