title: How to check values in HashMap<String, String> and setBackgroundResource when record = value?
body: <p>I have just started coding an Android App using Android Studio 2.1 and my app was sort of an offline messaging - this is using SQLite Database (basically compose of two tables message and contact).</p>
  
  <p>I am now in my last activity where I need to populate a list of message exchange from the contacts created. I was able to list them but without aesthetics. I would like to set different setBackgroundResource whenever the type is either a LEFT or RIGHT but was struggling to apply it.
  Below is my code:</p>
  
  <p>MessageRepo - the SQLite DBhelper:</p>
  
  <pre><code>    public ArrayList&lt;HashMap&lt;String, String&gt;&gt; getMessageListById(int fromid, int toid) {
      SQLiteDatabase db = helper.getWritableDatabase();
      String toquery = "SELECT " + MessageModel.messageId +
              ", " + MessageModel.fromId +
              ", " + MessageModel.toId +
              ", " + MessageModel.messageContent +
              ", 'RIGHT' AS type FROM " + MessageModel.tableMessage +
              " WHERE " + MessageModel.toId +
              " = ? AND " + MessageModel.fromId +
              " = ? ";
      String fromquery = "SELECT " + MessageModel.messageId +
              ", " + MessageModel.fromId +
              ", " + MessageModel.toId +
              ", " + MessageModel.messageContent +
              ", 'LEFT' AS type FROM " + MessageModel.tableMessage +
              " WHERE " + MessageModel.fromId +
              " = ? AND " + MessageModel.toId +
              " = ? ";
      String query = toquery +
              " UNION " + fromquery +
              " ORDER BY " + MessageModel.messageId;
  
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; messageList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
      Cursor cursor = db.rawQuery(query, new String[]{String.valueOf(fromid), String.valueOf(toid), String.valueOf(fromid), String.valueOf(toid)});
      if (cursor.moveToFirst()) {
          do {
              HashMap&lt;String, String&gt; messages = new HashMap&lt;String, String&gt;();
              messages.put("messageId", cursor.getString(0));
              messages.put("messageFromId", cursor.getString(1));
              messages.put("messageToId", cursor.getString(2));
              messages.put("messageContent", cursor.getString(3));
              messages.put("type", cursor.getString(4));
              messageList.add(messages);
          } while (cursor.moveToNext());
      }
      cursor.close();
      db.close();
      return messageList;
  }
  </code></pre>
  
  <p>Message Activity - this will display in a ListView but not working as I was intending it to display:</p>
  
  <pre><code>        ArrayList&lt;HashMap&lt;String, String&gt;&gt; messageList = messagehandler.getMessageListById(_fromid, _toid);
      if (messageList.size() != 0) {
          ListView listView = getListView();
          if(messageList.contains("RIGHT")) {
              listView.setBackgroundResource(R.drawable.right);
          } else {
              listView.setBackgroundResource(R.drawable.left);
          }
  
          ListAdapter adapter = new SimpleAdapter(MessageDetailActivity.this, messageList, R.layout.message, new String[]{"messageFromId", "messageToId", "messageContent"}, new int[]{R.id.FromId, R.id.ToId, R.id.message});
          setListAdapter(adapter);
          }
  </code></pre>
  
  <p>I've checked a lot of posts and I can't seem to make it work for me:
  <a href="https://stackoverflow.com/questions/17775077/the-constructor-arrayadapterarraylisthashmapstring-stringcontext-int-a">The constructor ArrayAdapter>>(Context, int, ArrayList>) is undefined</a>
  <a href="https://stackoverflow.com/questions/13109840/android-alternate-row-colors-in-listview">Android Alternate row Colors in ListView</a></p>
  
  <p>Thanks a lot in advance!</p>