package com.andela.webservice;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private TextView output;

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

        output = (TextView) findViewById(R.id.textView);
        output.setMovementMethod(new ScrollingMovementMethod());

        for(int i = 0; i<100; i++) {
            updateDisplay("Task " + i);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if(item.getItemId() == R.id.action_do_task) {
            updateDisplay("Task done!");
        }
        return true;
    }

    private void updateDisplay(String s) {
        output.append(s + "\n");
    }
}

@@ -25,16 +25,45 @@
 rvice;%0A%0A
+import android.os.AsyncTask;%0A
 import a
@@ -643,96 +643,8 @@
 ());
-%0A%0A        for(int i = 0; i%3C100; i++) %7B%0A            updateDisplay(%22Task %22 + i);%0A        %7D
 %0A   
@@ -879,103 +879,582 @@
     
-if(item.getItemId() == R.id.action_do_task) %7B%0A            updateDisplay(%22Task done!%22
+MyTask task = new MyTask();%0A        task.execute(%22param1%22, %22param2%22, %22param3%22);%0A        return true;%0A    %7D%0A%0A    private void updateDisplay(String s) %7B%0A        output.append(s + %22%5Cn%22);%0A    %7D%0A%0A    private class MyTask extends AsyncTask%3CString, String, String%3E %7B%0A        @Override%0A        protected void onPreExecute() %7B%0A            updateDisplay(%22Starting task%22);%0A        %7D%0A%0A        @Override%0A        protected String doInBackground(String... params) %7B%0A            for(int i = 0; i%3C params.length; i++) %7B%0A                publishProgress(%22working with %22 + params%5Bi%5D
 );%0A
+%0A
         
 %7D%0A  
@@ -1453,118 +1453,484 @@
     
-%7D%0A        return true;%0A    %7D%0A%0A    private void updateDisplay(String s) %7B%0A        output.append(s + %22%5Cn%22);
+        try %7B%0A                    Thread.sleep(1000);%0A                %7D catch (InterruptedException e) %7B%0A                    e.printStackTrace();%0A                %7D%0A            %7D%0A%0A            return %22Task Complete%22;%0A        %7D%0A%0A        @Override%0A        protected void onPostExecute(String result) %7B%0A            updateDisplay(result);%0A        %7D%0A%0A        @Override%0A        protected void onProgressUpdate(String... values) %7B%0A            updateDisplay(values%5B0%5D);%0A        %7D
 %0A    %7D%0A
+%0A%0A
 %7D%0A

Implement the AsyncTask in the MainActivity class and also the override the onProgressUpdate method