How can i save changed data in RecyclerView [closed]

asked 2018-09-12 07:16:39 -0600

50200 gravatar image

I am processing an image and getting 'data' from it. Then i show those in RecyclerView. I correct some data in RecyclerView if necessary. How to upload the corrected data with all the rest, Because even if the correction shows in RecyclerView it is not uploading the change ,Rather mistaken data are being uploaded. Can someone please help i am stuck for several days...

This is part of my mainActivity where i am adding the data to Recyclerview?

TextExtractionActivity.class

if (fileDirectory.isDirectory()) {
    listCroppedImages.clear();
    EmptyViewCroppedImage.setVisibility(View.GONE);
    RVCroppedImages.setVisibility(View.VISIBLE);
    listCroppedImages.clear();
    String PhotoPath[] = new String[100];
    final String StudentMatric[] = new String[100];
    final String AttendanceRecord[] = new String[100];

    for (int i = 1; i <= fileDirectory.listFiles().length; i++) {
        PhotoPath[i] = croppedImageDirectory + i + ".jpg";

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.ARGB_8888;
        Bitmap croppedimageold = BitmapFactory.decodeFile(PhotoPath[i], options);
        Bitmap croppedimagenew = Bitmap.createScaledBitmap(croppedimageold, 460, 66, true);

        StudentMatric[i] = TextImageProcess(croppedimagenew);
        AttendanceRecord[i] = CircleDetection(croppedimagenew, StudentMatric[i]);
        listCroppedImages.add(new CroppedImageModel(String.valueOf(i), PhotoPath[i], StudentMatric[i], AttendanceRecord[i]));

        btnUploadAttendance.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {


                for (int x = 1; x <= listCroppedImages.size(); x++) {
                    UploadData(StudentMatric[x], AttendanceRecord[x], x);
                }
            }
        });


    }
} else {
    EmptyViewCroppedImage.setVisibility(View.VISIBLE);
    RVCroppedImages.setVisibility(View.GONE);
}

-----------------------------------------------------------------------

public void UploadData(final String StudentMatric, final String AttendanceRecord, final int x) {
     ProgressUploadAttendance.setVisibility(View.VISIBLE);

    Query query = StudentsRef.orderByKey().equalTo(StudentMatric);
    query.addListenerForSingleValueEvent(new ValueEventListener() {
      @Override
      public void onDataChange(DataSnapshot dataSnapshot) {
          if (dataSnapshot.exists()) {
              int progress = x / listCroppedImages.size() * 100;
              DatabaseReference StudentMatricRef = StudentsRef.child(StudentMatric).child("Attendance").push();
              StudentMatricRef.child("Status").setValue(AttendanceRecord);
              StudentMatricRef.child("Date").setValue(getCurrentDate());
              ProgressUploadAttendance.setProgress(progress);
          } else {
              Toast.makeText(TextExtractionActivity.this, "Could not Find " + StudentMatric, Toast.LENGTH_LONG).show();
          }

      }

      @Override
      public void onCancelled(DatabaseError databaseError) {
          throw databaseError.toException(); // don't ignore errors
      }
  });

}

"RecyclerViewAdapterCroppedImages.class"

class RecyclerViewAdapterCroppedImages extends RecyclerView.Adapter<RecyclerViewAdapterCroppedImages.CroppedimageViewHolder> {

private Context mContext;
private List<CroppedImageModel> mData;
int x =0;

//   private String StudentMatric, studentMatric, AttendanceStatus, attendanceStatus;

public RecyclerViewAdapterCroppedImages() { }   //Constructor


public RecyclerViewAdapterCroppedImages(Context mContext, List<CroppedImageModel> mData) {
    this.mContext = mContext;
    this.mData = mData;
}


@Override
public CroppedimageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View croppedimageview;
    LayoutInflater mInflater = LayoutInflater.from(mContext);
    croppedimageview = mInflater.inflate(R.layout.item_cropped_image, parent, false);
    return new CroppedimageViewHolder(croppedimageview);
}

@Override
public void onBindViewHolder(final CroppedimageViewHolder holder, final int position) {

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;
    Bitmap croppedimageold = BitmapFactory.decodeFile(mData.get(position).getCroppedImagePath(), options);
    Bitmap croppedimagenew = Bitmap.createScaledBitmap(croppedimageold, 528, 80, true);


    holder.StudentNo.setText(mData.get(position).getStudentNo());
    holder.CroppedImage.setImageBitmap(croppedimagenew);
    holder.StudentId.setText(mData.get(position).getStudentMatric());
    holder.StudentStatus.setText(mData.get(position).getAttendanceRecord());

    holder.StudentStatus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mData.get(position).getAttendanceRecord().equals("Failed")) {
                holder.StudentStatus.setText("Present");
            } else if (mData.get(position).getAttendanceRecord().equals("Present")) {
                holder.StudentStatus.setText("Absent");
            } else if (mData.get(position).getAttendanceRecord().equals("Absent")) {
                holder.StudentStatus.setText("Present");
            }
        }
    });


}

@Override
public int getItemCount() {
    return mData.size();
}


class CroppedimageViewHolder extends RecyclerView.ViewHolder {
    TextView StudentNo, StudentId, StudentStatus;
    ImageView CroppedImage;

    private CroppedimageViewHolder(View itemView) {
        super(itemView);
        StudentNo = itemView.findViewById ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2018-09-14 00:00:55.966946

Comments

i do not see anything opencv related here.

(we can't help you with arbitrary android problems)

berak gravatar imageberak ( 2018-09-13 01:03:06 -0600 )edit