问题描述
这个问题是由于我以前的问题包含2个问题,而不是缩小到1
目标
$ p
$ b $ / b>
$ b 目前,当用户输入新报告时,事件报告节点中的用户事故报告数据将被覆盖。
用户发送的旧事件报告中的数据应与新数据一起保存。
这样当局就可以查看以前的报告和新的报告数据。 strong>问题
$ b 每次当前登录用户保存报告时,新建报告数据将覆盖旧的报告数据
保存数据的代码
private void submitReport(final String userReportDate,final String userReportTime,$ b $ final String userReportLocation,final String userReportDescription){
jReportCurrentUserID = FirebaseAuth.getInstance()。 getCurrentUser();
final String reportUserID = jReportCurrentUserID.getUid();
jReportByUserDatabase = FirebaseDatabase.getInstance()。getReference()。child(Incident Reports)。child(reportUserID);
HashMap< String,String> incidentReportUser = new HashMap<>();
incidentReportUser.put(date,userReportDate);
incidentReportUser.put(time,userReportTime);
incidentReportUser.put(location,userReportLocation);
incidentReportUser.put(description,userReportDescription);
jReportByUserDatabase.setValue(incidentReportUser).addOnCompleteListener(new OnCompleteListener< Void>(){
@Override
public void onComplete(@NonNull Task< Void> task){
if(task.isSuccessful()){
jReportLoad.dismiss();
Toast.makeText(getActivity(),Report was Sent,Toast.LENGTH_SHORT).show();
jReportDatePick.setText();
jReportTimeEnt.setText();
jReportLocationEnt.setText();
jReportDescriptionEnt.setText();
} else {
jReportLoad.dismiss();
Toast.makeText(getActivity(),Report failed to be sent,Toast.LENGTH_SHORT).show();
}
}
});
$ / code>
jReportByUserDatabase.push()。setValue(incidentReportUser)
这样写( push()
增加值而不是覆盖)。
This Question was created as my previous question contained 2 question instead of narrowing it down to 1
Aim
Users will be able to store new data without overwriting their previously submitted data
Description
Currently, the User's Incident Report data within the Incident Report node will be overwritten when the User enters a new Report.
The Data from the old Incident Report sent by the user should be kept along with the new data.
This way the authorities will be able to view the previous reports and also the new report data.
Problem
Everytime a the currently signed in user saves a "Report", the New report data will overwrite the Old report data
Codes for Saving Data
private void submitReport(final String userReportDate,final String userReportTime,
final String userReportLocation,final String userReportDescription) {
jReportCurrentUserID = FirebaseAuth.getInstance().getCurrentUser();
final String reportUserID = jReportCurrentUserID.getUid();
jReportByUserDatabase = FirebaseDatabase.getInstance().getReference().child("Incident Reports").child(reportUserID);
HashMap<String, String> incidentReportUser = new HashMap<>();
incidentReportUser.put("date", userReportDate);
incidentReportUser.put("time", userReportTime);
incidentReportUser.put("location", userReportLocation);
incidentReportUser.put("description", userReportDescription);
jReportByUserDatabase.setValue(incidentReportUser).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if(task.isSuccessful()){
jReportLoad.dismiss();
Toast.makeText(getActivity(), "Report was Sent", Toast.LENGTH_SHORT).show();
jReportDatePick.setText("");
jReportTimeEnt.setText("");
jReportLocationEnt.setText("");
jReportDescriptionEnt.setText("");
}else{
jReportLoad.dismiss();
Toast.makeText(getActivity(), "Report failed to be sent", Toast.LENGTH_SHORT).show();
}
}
});
}
jReportByUserDatabase.push().setValue(incidentReportUser)
Write it this way (push()
adds values instead of overriding).
这篇关于Android - Firebase - 在不覆盖旧数据的情况下保存新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!