package com.example.android.androidsimulator;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import java.util.ArrayList;

public class ContactsActivity extends AppCompatActivity {

    ContactsAdapter contactsAdapter;
    ArrayList<Contacts> contacts;
    Button buttonAddContact;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_contacts);

        buttonAddContact = (Button) findViewById(R.id.addContact_button);
        contacts = new ArrayList<>();

        // default values for test
        addContacts();

        // set OnClickListener
        setEvents();
    }

    private void setEvents() {
        buttonAddContact.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intentAddContact = new Intent(ContactsActivity.this, AddContactsActivity.class);
                startActivity(intentAddContact);
            }
        });
    }

    private void addContacts() {
        contacts.add(new Contacts("Contact One", Integer.valueOf(912976342)));
        contacts.add(new Contacts("Contact Two", Integer.valueOf(912564789)));
        contacts.add(new Contacts("Contact Three", Integer.valueOf(912098123)));

        addAdapter();
    }

    private void addAdapter() {
        contactsAdapter = new ContactsAdapter(this, contacts);
        ListView listView = (ListView) findViewById(R.id.list_contacts);
        listView.setAdapter(contactsAdapter);
    }
}

@@ -71,16 +71,103 @@
 Intent;%0A
+import android.content.SharedPreferences;%0Aimport android.preference.PreferenceManager;%0A
 import a
@@ -418,39 +418,37 @@
     
-ContactsAdapter contactsAdapter
+SharedPreferences preferences
 ;%0A  
@@ -479,16 +479,53 @@
 ntacts;%0A
+    ContactsAdapter contactsAdapter;%0A
     Butt
@@ -713,17 +713,16 @@
 tacts);%0A
-%0A
         
@@ -787,24 +787,25 @@
 utton);%0A
+%0A
         
 contacts
@@ -788,32 +788,40 @@
 tton);%0A%0A        
+// show 
 contacts = new A
@@ -817,64 +817,29 @@
 cts 
-= new ArrayList%3C%3E();%0A%0A        // default values for test
+from internal storage
 %0A   
@@ -843,19 +843,20 @@
         
-add
+show
 Contacts
@@ -911,32 +911,136 @@
 vents();%0A    %7D%0A%0A
+    @Override%0A    protected void onResume() %7B%0A        super.onResume();%0A%0A        showContacts();%0A    %7D%0A%0A
     private void
@@ -1382,31 +1382,31 @@
 %7D%0A%0A    p
-rivate
+ublic
  void 
-add
+show
 Contacts
@@ -1430,230 +1430,450 @@
 acts
-.add(new Contacts(%22Contact One%22, Integer.valueOf(912976342)));%0A        contacts.add(new Contacts(%22Contact Two%22, Integer.valueOf(912564789)));%0A        contacts.add(new Contacts(%22Contact Three%22, Integer.valueOf(912098123)));
+ = new ArrayList%3C%3E();%0A        preferences = PreferenceManager.getDefaultSharedPreferences(this);%0A        int totalContacts = preferences.getInt(%22totalContacts%22, 0);%0A%0A        for (int index = 1; index %3C= totalContacts; index++) %7B%0A            String name = preferences.getString(%22nameContact%22 + index, %22%22);%0A            int number = preferences.getInt(%22numberContact%22 + index, 0);%0A%0A            contacts.add(new Contacts(name, number));%0A        %7D
 %0A%0A  
@@ -1900,30 +1900,29 @@
     %7D%0A%0A    p
-rivate
+ublic
  void addAda

Add method to show contacts from internal storage