package coderefactory.net.popmovies;

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

import java.util.List;

public class MovieAdapter extends ArrayAdapter<Movie> {

    public MovieAdapter(final Activity context, final List<Movie> movies) {
        super(context, 0, movies);
    }

    @NonNull
    @Override
    public View getView(final int position, final View convertView, final ViewGroup parent) {
        final View rootView;
        if (convertView == null) {
            rootView = LayoutInflater.from(getContext()).inflate(R.layout.list_item_movie, parent, false);
        } else {
            rootView = convertView;
        }
        final Movie movie = getItem(position);

        final TextView titleView = (TextView) rootView.findViewById(R.id.movie_title);
        titleView.setText(movie.getTitle());

        final TextView releaseView = (TextView) rootView.findViewById(R.id.movie_released);
        releaseView.setText(String.valueOf(movie.getReleased()));

        return rootView;
    }
}

@@ -346,16 +346,52 @@
 vie%3E %7B%0A%0A
+    private ViewHolder viewHolder;%0A%0A
     publ
@@ -640,20 +640,20 @@
 al View 
-root
+item
 View;%0A  
@@ -693,28 +693,28 @@
             
-root
+item
 View = Layou
@@ -804,39 +804,182 @@
     
-%7D else %7B%0A            rootView =
+    viewHolder = new ViewHolder(itemView);%0A            itemView.setTag(viewHolder);%0A        %7D else %7B%0A            itemView = convertView;%0A            viewHolder = (ViewHolder)
  con
@@ -978,32 +978,41 @@
 der) convertView
+.getTag()
 ;%0A        %7D%0A    
@@ -1011,196 +1011,409 @@
   %7D%0A
-        final Movie movie = getItem(position);%0A%0A        final TextView titleView = (TextView) rootView.findViewById(R.id.movie_title
+%0A        populateView(position);%0A%0A        return itemView;%0A    %7D%0A%0A    private void populateView(final int position) %7B%0A        final Movie movie = getItem(position);%0A%0A        viewHolder.titleView.setText(movie.getTitle());%0A        viewHolder.releaseView.setText(String.valueOf(movie.getReleased())
 );%0A    
+%7D%0A%0A
     
-titleView.setText(movie.getTitle());%0A%0A
+private static class ViewHolder %7B%0A        private final TextView titleView;%0A 
        
+private
  fin
@@ -1435,16 +1435,90 @@
 easeView
+;%0A%0A        private ViewHolder(final View itemView) %7B%0A            titleView
  = (Text
@@ -1523,20 +1523,20 @@
 xtView) 
-root
+item
 View.fin
@@ -1560,19 +1560,20 @@
 vie_
-released);%0A
+title);%0A    
     
@@ -1591,64 +1591,74 @@
 View
-.setText(String.valueOf(movie.getR
+ = (TextView) itemView.findViewById(R.id.movie_r
 eleased
-())
 );%0A
-%0A
         
 retu
@@ -1657,24 +1657,9 @@
     
-return rootView;
+%7D
 %0A   

Introduce ViewHolder pattern into ArrayAdapter