title: How can I manage to arrange an ArrayList of a custom Object in alphabetical order, which contains two different strings?
body: <p>Now in detail. I am writing an App for a dictionary. For that I have created a custom Object called Word. This Word contains the term and its' corresponding translation:</p>
  
  <pre><code>public class Word implements Serializable {
  
  private int _id;
  private int wordType;
  private String engWordSi;
  private String okyWordPl;
  private String engWordPl;
  private String okyWordSi;
  private String engEx;
  private String okyEx;
  
  /** Creates a custom class, which allows save a term, it's translation, as well as the plural and example in both
   * languages
   * @param   _id     saves the Id of the Word in the Database
   * @param engWordSi saves the English translation of the word
   * @param okyWordSi saves the Oshikwanyama translation of the word
   * @param wordType saves the type of word in form of a number:
   *                 0 = phrase; 1 = noun; 2 = verb; 3 = adjective; 4 = pronoun; 5 = other
   */
  
  public Word(int _id, int wordType, String engWordSi, String okyWordSi){
      this._id = _id;
      this.wordType = wordType;
      this.engWordSi = engWordSi;
      this.okyWordSi = okyWordSi;
  }public int get_id(){
      return _id;
  }
  public void set_id(int i){
      _id = i;
  }
  public int getWordType(){
      return wordType;
  }
  public void setWordType(int i){
      if(i &lt; 0 || i &gt; 6){
          return;
      }
      wordType = i;
  }
  public String getEngWordSi(){
      return engWordSi;
  }
  public void setEngWordSi(String word){
      engWordSi = word;
  }
  public String getOkyWordSi(){
      return okyWordSi;
  }
  public void setOkyWordSi(String word){
      okyWordSi = word;
  }
  public String getEngWordPl(){
      return engWordPl;
  }
  public void setEngWordPl(String word){
      engWordPl = word;
  }
  public String getOkyWordPl(){
      return okyWordPl;
  }
  public void setOkyWordPl(String word){
      okyWordPl = word;
  }
  public String getEngEx(){
      return engEx;
  }
  public void setEngEx(String word){
      engEx = word;
  }
  public String getOkyEx(){
      return okyEx;
  }
  public void setOkyEx(String word){
      okyEx = word;
  }
  </code></pre>
  
  <p>The data is loaded via a php file connected to the database. The ORDER BY statement only allows me to choose one language to order the results by. But what I need is, that the search term, which might be found in words of both languages, defines if the English word or the Oshikwanyama word is the word which is being arranged in the order. I have check which translation to use in each case. My guess would be to do it in onPostExecute(). The data is returned by the PHP file in the JSON format. From there I put them into an ArrayList.</p>
  
  <pre><code>private class Query extends AsyncTask&lt;Void, Void, Void&gt;{
      @Override
      protected void onPostExecute(Void aVoid) {
          try{
              JSONArray jsonArray = new JSONArray(result);
              for (int i = 0; i &lt; jsonArray.length(); i++){
                  JSONObject jsonObject = jsonArray.getJSONObject(i);
                  Word word = new Word(jsonObject.getInt("_id"), jsonObject.getInt("type"), jsonObject.getString("eng"), jsonObject.getString("oky") );
                  arrayList.add(word);
                  Log.d("JSON", word.toString());
              }
          }catch (JSONException e){
              e.printStackTrace();
          }
          ProgressBar bar = (ProgressBar) findViewById(R.id.bar);
          bar.setVisibility(View.GONE);
          Button button = (Button) findViewById(R.id.SearchButton);
          button.setVisibility(View.VISIBLE);
          super.onPostExecute(aVoid);
          if (arrayList.isEmpty()){
              Toast.makeText(SearchActivity.this, "Unfortunately there were no results, the missing word was sent to our developers.", Toast.LENGTH_LONG).show();
              return;
          }
          Intent intent = new Intent(SearchActivity.this, ResultActivity.class);
          ItemDetailsWrapper wrapper = new ItemDetailsWrapper(arrayList);
          intent.putExtra("results", wrapper);
          intent.putExtra("term", searchTerm);
          startActivity(intent);
      }
  
      InputStream inputStream = null;
      String result = "";
  
      @Override
      protected void onPreExecute() {
          if (arrayList != null){
          arrayList.clear();}
          super.onPreExecute();
      }
  
      @Override
      protected Void doInBackground(Void... voids) {
          try{
              HttpClient httpClient = new DefaultHttpClient();
              HttpPost httpPost = new HttpPost(uri.toString());
              //httpPost.setEntity(new UrlEncodedFormEntity(null));
              HttpResponse httpResponse = httpClient.execute(httpPost);
              HttpEntity httpEntity = httpResponse.getEntity();
              inputStream = httpEntity.getContent();
          }
          catch (UnsupportedEncodingException e1){
              e1.printStackTrace();
          } catch (ClientProtocolException e2){
              e2.printStackTrace();
          }catch (IllegalStateException e3){
              e3.printStackTrace();
          }catch (IOException e4){
              e4.printStackTrace();
          }try{
              BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
              StringBuilder stringBuilder = new StringBuilder();
              String line = null;
              while ((line = bufferedReader.readLine()) != null){
                  stringBuilder.append(line + "\n");
              }
              inputStream.close();
              result = stringBuilder.toString();
          }catch (IOException e){
              e.printStackTrace();
          }
          return null;
      }
  
  }}
  </code></pre>
  
  <p>I already have a place to check whether the term searched for is contained in the English or Oshikwanyama word. There I use it to define the flag used in the layout.</p>
  
  <pre><code>public class WordAdapter extends ArrayAdapter&lt;Word&gt; {
  private Context mContext;
  private List&lt;Word&gt; wordList = new ArrayList&lt;&gt;();
  private int srcCode;
  private String term;
  
  /** uses words and puts them into a list
   * 
   * @param context stores the context of the calling activity
   * @param list stores the ArrayList that was passed into the constructor, and which contains the
   *             content
   * @param searchTerm stores the term that was searched for in SearchActivity to later compare it
   *                   to the contents of the Word and to arrange the correct flag for the source
   *                   language
   */
  
  public WordAdapter(@NonNull Context context, ArrayList&lt;Word&gt; list, String searchTerm) {
      super(context, 0 , list);
      mContext = context;
      wordList = list;
      term = searchTerm;
  }
  
  @NonNull
  @Override
  public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
      View listItem = convertView;
      if(listItem == null){
          listItem = LayoutInflater.from(mContext).inflate(R.layout.list_item,parent,false);}
      final Word currentWord = wordList.get(position);
      //Add Images for the flags of the countries and the flag
      final TextView sourceTerm = (TextView) listItem.findViewById(R.id.searchTerm);
      final TextView translationTerm = (TextView) listItem.findViewById(R.id.translationTerm);
      ImageView flag = (ImageView) listItem.findViewById(R.id.src_flag);
      ImageButton button = (ImageButton) listItem.findViewById(R.id.flag);
      button.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent intent = new Intent(getContext(), EditorActivity.class);
              intent.putExtra("mode", "report");
              intent.putExtra("id", currentWord.get_id());
              intent.putExtra("source", sourceTerm.getText());
              intent.putExtra("trans", translationTerm.getText());
              getContext().startActivity(intent);
          }
      });
      if (currentWord.getOkyWordPl() == null){
          currentWord.setOkyWordPl("");
      }
      if (currentWord.getEngWordPl() == null){
          currentWord.setEngWordPl("");
      }
      if (currentWord.getEngWordSi().contains(term) || currentWord.getEngWordPl().contains(term)){
          srcCode = 0;
      }
      if (currentWord.getOkyWordSi().contains(term) || currentWord.getOkyWordPl().contains(term)){
          srcCode = 1;
      }
      if (srcCode == 0){
              sourceTerm.setText(currentWord.getEngWordSi());
              translationTerm.setText(currentWord.getOkyWordSi());
              flag.setImageResource(R.drawable.britain);
      }
      if (srcCode == 1){
          sourceTerm.setText(currentWord.getOkyWordSi());
          translationTerm.setText(currentWord.getEngWordSi());
          flag.setImageResource(R.drawable.namibia);
      }
      return listItem;
  }}
  </code></pre>
  
  <p>Thank you in advance. :)</p>
  
  <p>EDIT: </p>
  
  <p>Adding example Words:
  1.
  EngWordSi: good
  OkyWordSi: nawa
  wordType: 2
  2.
  EngWordSi: good morning
  OkyWordSi: wa lele po?
  wordType: 0
  3.
  EngWordSi: morning
  OkyWordSi: ongula
  WordType: 1</p>