My goal is to create an app that in basics have two different activities, one in which the user creates a "protocol" (EditorActivity) and on in which the user can view them in a listview(CatalogActivity). If there is something wrong with a protocol, the user must be able to press one of the list view items in the listview, and from there go back in to the EditorActivity and edit the specific item.
My problem is that I have not figured out how to get the old data from the CatalogActivity in to the EditorActivity.
From firebase console: [Firebase structure][1]
CustomProtocol:
public class CustomProtocol {
public String dateDrill;
public String pileID;
public boolean cleaned;
public CustomProtocol() {
}
public CustomProtocol(String pileID,
String dateDrill,
boolean cleaned) {
this.pileID = pileID;
this.dateDrill = dateDrill;
this.cleaned = cleaned;
}
public void setPileID(String pileID) {
this.pileID = pileID;
}
public String getPileID() {
return pileID;
}
public void setDateDrill(String dateDrill) {
this.dateDrill = dateDrill;
}
public String getDateDrill() {
return dateDrill;
}
}
Snippet from CatalogActivity:
final String projectNumber = projectPrefs.getString(getString(R.string.settings_project_number_key), getString(R.string.settings_project_number_by_default));
mFirebaseDatabase = FirebaseDatabase.getInstance();
mProtocolDatabaseReference = mFirebaseDatabase.getReference().child(projectNumber);
List<CustomProtocol> protocols = new ArrayList<>();
mProtocolAdapter = new ProtocolAdapter(this, R.layout.item_protocol, protocols);
mProtocolListView.setAdapter(mProtocolAdapter);
attachDatabaseReadListener();
mProtocolListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent intent = new Intent(CatalogActivity.this, EditorActivity.class);
intent.putExtra("Exiting protocol", EXISTING_PROTOCOL);
}
});
}
EditorActivty:
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_editor);
EXISTING_PROTOCOL = intent.getBooleanExtra("Exiting protocol", false);
mEditorFirebaseDatabase = FirebaseDatabase.getInstance();
mEditorProtocolDatabaseReference =
mEditorFirebaseDatabase.getReference().child(projectNumber);
if (EXISTING_PROTOCOL)
mProtocolDatabaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//WHAT GOES HERE SO THAT I CAN POPULATE THE TEXTVIEWS IN THE ACTIVITY_EDITOR WITH THE EXISTING VALUES?
}}
And after this I'm stuck. I guess that I must add something more to the databasereference in the EditorActivity, but I cannot figure out what? Since I don't know the pileID until after the listitem has been clicked? Is there an easier way to do this?
Thank you in advance!