private void changeApprovalStatus(final int statusID, final String keyForUpdatableDate) {
    activity.startLoading();
    new Thread(
            new Runnable() {
              @Override
              public void run() {
                String tempResult;
                try {
                  tempResult =
                      app.onlineGateway.saveCapex(
                          activity.capexHeader.getJSONFromUpdatingCapex(
                              statusID, keyForUpdatableDate, app),
                          activity.capexHeader.jsonize(app));
                } catch (Exception e) {
                  tempResult = e.getMessage();
                }

                final String result = tempResult;
                new Handler(Looper.getMainLooper())
                    .post(
                        new Runnable() {
                          @Override
                          public void run() {
                            if (result.equals("OK")) {
                              activity.finishLoading();
                              Toast.makeText(activity, "Updated Successfully!", Toast.LENGTH_SHORT)
                                  .show();
                              activity.finish();
                            } else activity.finishLoading();
                          }
                        });
              }
            })
        .start();
  }
 @Override
 public void onClick(View v) {
   if (v == actionbarButtonBack || v == actionbarTitle) linearNavFragmentActivity.onBackPressed();
   else if (v == buttonApprove) {
     if (activity.capexHeader.getStatusID() == CapexHeader.CAPEXHEADERID_SUBMITTED)
       changeApprovalStatus(
           CapexHeader.CAPEXHEADERID_APPROVEDBYCM, "DateProcessedByCountryManager");
     else if (activity.capexHeader.getStatusID() == CapexHeader.CAPEXHEADERID_APPROVEDBYCM)
       changeApprovalStatus(
           CapexHeader.CAPEXHEADERID_APPROVEDBYRM, "DateProcessedByRegionalManager");
     else if (activity.capexHeader.getStatusID() == CapexHeader.CAPEXHEADERID_APPROVEDBYRM)
       changeApprovalStatus(CapexHeader.CAPEXHEADERID_APPROVEDBYCFO, "NA");
     else if (activity.capexHeader.getStatusID() == CapexHeader.CAPEXHEADERID_APPROVEDBYCFO)
       changeApprovalStatus(CapexHeader.CAPEXHEADERID_APPROVEDBYCEO, "NA");
   } else if (v == buttonReject) {
     if (activity.capexHeader.getStatusID() == CapexHeader.CAPEXHEADERID_SUBMITTED)
       changeApprovalStatus(
           CapexHeader.CAPEXHEADERID_REJECTEDBYCM, "DateProcessedByCountryManager");
     else if (activity.capexHeader.getStatusID() == CapexHeader.CAPEXHEADERID_REJECTEDBYCM)
       changeApprovalStatus(
           CapexHeader.CAPEXHEADERID_REJECTEDBYRM, "DateProcessedByRegionalManager");
     else if (activity.capexHeader.getStatusID() == CapexHeader.CAPEXHEADERID_REJECTEDBYRM)
       changeApprovalStatus(CapexHeader.CAPEXHEADERID_REJECTEDBYCFO, "NA");
     else if (activity.capexHeader.getStatusID() == CapexHeader.CAPEXHEADERID_REJECTEDBYCFO)
       changeApprovalStatus(CapexHeader.CAPEXHEADERID_REJECTEDBYCEO, "NA");
   } else if (v == buttonReturn) {
     changeApprovalStatus(CapexHeader.CAPEXHEADERID_OPEN, "NA");
   } else if (v == fieldAttachment) {
     if (!activity.capexHeader.getAttachedCer().equals(CapexHeader.NOATTACHMENT)) {
       try {
         System.out.println("SALTX will click attachment");
         Document doc = activity.capexHeader.getDocuments().get(0);
         int docID = doc.getDocID();
         int objectTypeID = doc.getObjectTypeID();
         int refID = doc.getRefID();
         String filename = doc.getDocName();
         activity.startLoading();
         app.fileManager.downloadDocument(docID, refID, objectTypeID, filename, this);
       } catch (Exception e) {
         e.printStackTrace();
         activity.finishLoading();
         app.showMessageDialog(activity, e.getMessage());
       }
     }
   }
 }
  @Override
  public void onResume() {
    super.onResume();

    if (activity.capexHeader == null) {
      activity.startLoading();
      new Thread(
              new Runnable() {
                @Override
                public void run() {
                  Object tempResult;
                  try {
                    tempResult = app.onlineGateway.getCapexHeaderDetail(activity.capexHeaderID);
                  } catch (Exception e) {
                    tempResult = e.getMessage();
                  }

                  final Object result = tempResult;
                  new Handler(Looper.getMainLooper())
                      .post(
                          new Runnable() {
                            @Override
                            public void run() {
                              if (result instanceof String)
                                activity.finishLoading(result.toString());
                              else {
                                try {
                                  activity.capexHeader = new CapexHeader((JSONObject) result);
                                  System.out.println("SALTX capexheader " + activity.capexHeader);
                                  updateViews();
                                  activity.finishLoading();
                                  ((AnimationDrawable) ivLineItemLoader.getDrawable()).start();
                                  syncLineItems();
                                } catch (Exception e) {
                                  e.printStackTrace();
                                  System.out.println("SALTX " + e.getMessage());
                                  ivLineItemLoader.setVisibility(View.GONE);
                                  tvLineItemHeader.setText("Asset Detail Line Items");
                                  activity.finishLoading(e.getMessage());
                                }
                              }
                            }
                          });
                }
              })
          .start();
    } else {
      updateViews();

      tvLineItemHeader.setText("Asset Detail Line Items");
      ivLineItemLoader.setVisibility(View.GONE);
      for (int i = 0; i < activity.capexLineItems.size(); i++) {
        final int pos = i;
        CapexLineItem item = activity.capexLineItems.get(i);
        View v = LayoutInflater.from(activity).inflate(R.layout.node_tvwithsepartorabove, null);
        v.setOnClickListener(
            new View.OnClickListener() {

              @Override
              public void onClick(View v) {
                linearNavFragmentActivity.changePage(
                    CapexForApprovalLineItemDetailsFragment.newInstance(pos));
              }
            });

        ((TextView) v.findViewById(R.id.tviews_node_tvwithseparator))
            .setText(item.getCapexNumber());
        containersLineItems.addView(v);
      }
    }
  }