package com.spectacularjourney.todoapp;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.spectacularjourney.todoapp.storage.Task;

import java.util.ArrayList;

/**
 * Created by jeff on 9/23/15.
 */
public class TasksAdapter extends ArrayAdapter<Task> {

    public TasksAdapter(Context context, ArrayList<Task> tasks) {
        super(context, 0, tasks);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Task task = getItem(position);

        if (convertView == null) {
            convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_task, parent, false);
        }

        TextView tvName = (TextView) convertView.findViewById(R.id.tvName);
        tvName.setText(task.name);

        TextView tvPosition = (TextView) convertView.findViewById(R.id.tvPosition);
        tvPosition.setText(Integer.toString(task.position));

        return convertView;
    }
}

@@ -405,16 +405,111 @@
 ask%3E %7B%0A%0A
+    private static class ViewHolder %7B%0A        TextView name;%0A        TextView position;%0A    %7D%0A%0A
     publ
@@ -733,24 +733,55 @@
 position);%0A%0A
+        ViewHolder viewHolder;%0A
         if (
@@ -799,24 +799,67 @@
  == null) %7B%0A
+            viewHolder = new ViewHolder();%0A
             
@@ -954,39 +954,33 @@
 e);%0A
-   
+%0A
      
-%7D%0A%0A
        
- TextView tvN
+viewHolder.n
 ame 
@@ -1043,56 +1043,24 @@
     
-tvName.setText(task.name);%0A%0A        TextView tvP
+    viewHolder.p
 osit
@@ -1119,24 +1119,25 @@
 ition);%0A
+%0A
         
 tvPositi
@@ -1128,19 +1128,204 @@
         
-tvP
+    convertView.setTag(viewHolder);%0A        %7D else %7B%0A            viewHolder = (ViewHolder) convertView.getTag();%0A        %7D%0A%0A        viewHolder.name.setText(task.name);%0A        viewHolder.p
 osition.

Use ViewHolder pattern