package com.example.android.androidsimulator.adapters;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.android.androidsimulator.data.Messages;
import com.example.android.androidsimulator.R;

import java.util.ArrayList;


public class MessagesAdapter extends ArrayAdapter<Messages> {

    public MessagesAdapter(Activity context, ArrayList<Messages> messages) {
        super(context, 0, messages);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View listItemView = convertView;
        if (listItemView == null) {
            listItemView = LayoutInflater.from(getContext()).inflate(
                    R.layout.list_messages, parent, false);
        }

        final Messages currentListMessage = getItem(position);

        // user message
        TextView userTextView = (TextView) listItemView.findViewById(R.id.user_textView);
        userTextView.setText(currentListMessage.getUser());

        // last message of list
        TextView messageTextVIew = (TextView) listItemView.findViewById(R.id.message_textView);
        messageTextVIew.setText(currentListMessage.getMessage());

        // date of last message
        TextView dateTextView = (TextView) listItemView.findViewById(R.id.date_textView);
        dateTextView.setText(currentListMessage.getDate());

        return listItemView;
    }
}

@@ -78,16 +78,134 @@
 tivity;%0A
+import android.content.Intent;%0Aimport android.content.SharedPreferences;%0Aimport android.preference.PreferenceManager;%0A
 import a
@@ -228,24 +228,24 @@
 utInflater;%0A
-
 import andro
@@ -358,16 +358,95 @@
 tView;%0A%0A
+import com.example.android.androidsimulator.activities.SelectedMessageContact;%0A
 import c
@@ -1160,32 +1160,38 @@
 message%0A        
+final 
 TextView userTex
@@ -1626,32 +1626,32 @@
 date_textView);%0A
-
         dateText
@@ -1691,24 +1691,1052 @@
 etDate());%0A%0A
+        listItemView.setOnClickListener(new View.OnClickListener() %7B%0A            @Override%0A            public void onClick(View v) %7B%0A                // check the id of contact by name%0A                SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getContext());%0A%0A                String checkName = currentListMessage.getUser();%0A                int totalContacts = preferences.getInt(%22totalContacts%22, 0);%0A                int checkId = 0;%0A%0A                for (int index = 1; index %3C= totalContacts; index++) %7B%0A                    String name = preferences.getString(%22nameContact%22 + index, %22%22);%0A%0A                    if (checkName == name) %7B%0A                        checkId = index;%0A                        index = totalContacts;%0A                    %7D%0A%0A                %7D%0A%0A                Intent intent = new Intent(getContext(), SelectedMessageContact.class);%0A                intent.putExtra(%22selectedContact%22, checkId);%0A                getContext().startActivity(intent);%0A            %7D%0A        %7D);%0A%0A
         retu

Add method to open the selected conversation