title: How to change the appearance of an android view with a click listener and background worker?
body: <p>I have an android app that users can use to check into a course at a certain time. Their daily schedule shows up on a RecyclerView as a series of CardViews. Each CardView has basic information about each class, including instructor name, course title, attendance status, etc..
   The app communicates with a MySQL database through a php script which is called from an AsyncTask background worker. In the PostExecute method, the app receives a result from the php script ("Present" if checking in on time, "Tardy" if late, "Absent" if totally missed) to show in an AlertDialog. The PostExecute method also sets a String variable to equal the result.</p>
  
  <pre><code>The background worker is called from a click listener like so:
  
  baf.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
  
                      int bright = status.getResources().getColor(R.color.colorPresent);
                      status.setBackgroundColor(bright);
  
                      lol = getAdapterPosition()+1;
                      SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
                      Calendar c = Calendar.getInstance();
                      String time = sdf.format(c.getTime());
                      Log.d("Current Time",time);
                      String type="checkin";
                      PresentBackgroundWorker presentBackgroundWorker = new PresentBackgroundWorker(getActivity());
                      presentBackgroundWorker.execute(type,date,time, "t"+String.valueOf(lol));
                      String aaa = ontime;
                      status.setText(aaa);
  
                  }
              });
  </code></pre>
  
  <p>The variable ontime (global variable) is the result from the php script, and its value is set from the background worker like so:</p>
  
  <pre><code>protected void onPostExecute(String result) {
  
          writeitout(result);
  
          alertDialog.setMessage(result);
  
  
          alertDialog.show();
      }
  
  private void writeitout(String string) {
      ontime = string;
      Log.d("STATS",ontime);
  }
  </code></pre>
  
  <p>Based on the <code>Log.d()</code> commands, the ontime variable is changing appropriately, but the change to the 'status' TextView is delayed by one click. That is, the result for the previous course, shows up for the present course. How do I make sure the changes in the ontime variable show up on time?</p>
  
  <p><strong>EDIT: ADDED ORIGINAL COURSEADAPTER</strong></p>
  
  <pre><code>public class CourseAdapter extends RecyclerView.Adapter&lt;CourseAdapter.MyViewHolder&gt; {
      private List&lt;Course&gt; courseList;
  
  
      public CourseAdapter(List&lt;Course&gt; sc) { this.courseList = sc; }
  
      public class MyViewHolder extends  RecyclerView.ViewHolder {
          TextView title, teacher, type, status;
          FloatingActionButton baf;
          View subIten;
          int lol;
  
          public MyViewHolder(View view) {
              super(view);
              title = (TextView) view.findViewById(R.id.texttitle);
              teacher = (TextView) view.findViewById(R.id.textteach);
              type = (TextView) view.findViewById(R.id.texttype);
              baf = (FloatingActionButton) view.findViewById(R.id.fab);
              status = view.findViewById(R.id.textstatus);
              subIten = (View) view.findViewById(R.id.sub_item);
          }
          private void bind(Course course) {
              title.setText(course.getTitle());
              teacher.setText(course.getTeacher());
              type.setText(course.getType());
              baf.setImageResource(course.getPhotoID());
              baf.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
  
                      int bright = status.getResources().getColor(R.color.colorPresent);
                      status.setBackgroundColor(bright);
  
                      lol = getAdapterPosition()+1;
                      SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
                      Calendar c = Calendar.getInstance();
                      String time = sdf.format(c.getTime());
                      Log.d("Current Time",time);
                      String type="checkin";
                      PresentBackgroundWorker presentBackgroundWorker = new PresentBackgroundWorker(getActivity());
                      presentBackgroundWorker.execute(type,date,time, "t"+String.valueOf(lol));
  
                  }
              });
          }
      }
  
      @Override
      public CourseAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View itemView = LayoutInflater.from(parent.getContext())
                  .inflate(R.layout.cardview, parent, false);
  
          MyViewHolder viewHolder = new MyViewHolder(itemView);
          return viewHolder;
      }
  
      @Override
      public void onBindViewHolder(final CourseAdapter.MyViewHolder holder, final int position) {
          final Course course = courseList.get(position);
          holder.bind(course);
  
      }
  
      public int getItemCount() {
          return courseList.size();
      }
  }
  </code></pre>