从 firebase 中的 MainActivity 上传 RecyclerView 的所有数据
uploading all data of RecyclerView from MainActivity in firebase
我正在处理一些图像并将处理过程中的数据添加到 RecyclerView 的数组列表中。现在我想通过检查列表中的 object 是否与 firebase 数据库 child 匹配,然后将第二个 object 插入 child 来将所有数据插入到 firebase 数据库中firebase 的匹配 child 一一。如何通过主 activity 中的单个按钮而不是 RecyclerView 来实现这一点。
下面是我如何使用 ModelClass 在 RecyclerView 中插入数据。
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]));
}
} else {
EmptyViewCroppedImage.setVisibility(View.VISIBLE);
RVCroppedImages.setVisibility(View.GONE);
}
-------------------------
}
public String TextImageProcess(Bitmap image){
----------------
return String x;
};
public String CircleDetection(Bitmap image, String y){
----------------------
return String z;
}
想要的是
btnUploadData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for(i=1; i=listCroppedImages.size(); i++)
if(StudentMatric[i].isequalto(firbasedataRef.getKey())){
DatabaseReference current_user_db = FirebaseDatabase.getInstance().getReference().child(StudentMatric[i]).child("Attendance Record");
Map newPost = new HashMap();
newPost.put("Attendance", Attendance[i]);
current_user_db.updateChildren(newPost);
}
});
我现在的问题是如何获取 btnUploadData.setOnclickliastener 中的数据 (Student[i], Attendance[i]) 并将数组列表的第一个元素与 firebase 键匹配,然后将下一个元素插入到child 的关键?我被困在这里好几天了。任何建议都将非常适用。提前致谢
我没想到答案这么简单..这就是我所做的
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
}
});
}
我正在处理一些图像并将处理过程中的数据添加到 RecyclerView 的数组列表中。现在我想通过检查列表中的 object 是否与 firebase 数据库 child 匹配,然后将第二个 object 插入 child 来将所有数据插入到 firebase 数据库中firebase 的匹配 child 一一。如何通过主 activity 中的单个按钮而不是 RecyclerView 来实现这一点。
下面是我如何使用 ModelClass 在 RecyclerView 中插入数据。
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]));
}
} else {
EmptyViewCroppedImage.setVisibility(View.VISIBLE);
RVCroppedImages.setVisibility(View.GONE);
}
-------------------------
}
public String TextImageProcess(Bitmap image){
----------------
return String x;
};
public String CircleDetection(Bitmap image, String y){
----------------------
return String z;
}
想要的是
btnUploadData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for(i=1; i=listCroppedImages.size(); i++)
if(StudentMatric[i].isequalto(firbasedataRef.getKey())){
DatabaseReference current_user_db = FirebaseDatabase.getInstance().getReference().child(StudentMatric[i]).child("Attendance Record");
Map newPost = new HashMap();
newPost.put("Attendance", Attendance[i]);
current_user_db.updateChildren(newPost);
}
});
我现在的问题是如何获取 btnUploadData.setOnclickliastener 中的数据 (Student[i], Attendance[i]) 并将数组列表的第一个元素与 firebase 键匹配,然后将下一个元素插入到child 的关键?我被困在这里好几天了。任何建议都将非常适用。提前致谢
我没想到答案这么简单..这就是我所做的
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
}
});
}