我有3个活动,分别是AddAds,ViewAds和EditAds。用户添加新添加的内容后,它将在ViewAds中显示/检索,当用户单击UpdateButton时,它将转到EditAds。在这里,我无法弄清楚为什么不能从以前的数据更新数据?有人可以帮助我,我在哪里错过我的编码?预先感谢...
UpdateButton编码:-
UpdateAdvertisementButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SendUserToViewAdsActivity();
String id = databaseAdvertisement.push().getKey();
String tuitionimage = image;
String providername = EditProviderName.getText().toString();
String providergender = EditProviderGender.getSelectedItem().toString();;
if (TextUtils.isEmpty(tuitionimage)) {
Toast.makeText(EditAdsActivity.this, "Insert tuition image.", Toast.LENGTH_SHORT).show();
} else if (TextUtils.isEmpty(providername)) {
Toast.makeText(EditAdsActivity.this, "Enter tuition provider name.", Toast.LENGTH_SHORT).show();
} else if(EditProviderGender.getSelectedItemPosition() == 0) {
Toast.makeText(EditAdsActivity.this, "Select the options listed, either male or female.", Toast.LENGTH_SHORT).show();
} else {
loadingBar.setTitle("Updating Tuition Centre");
loadingBar.setMessage("Please wait while we are updating your ads in our system.");
loadingBar.show();
loadingBar.setCanceledOnTouchOutside(true);
uploadImageAndGetURL(databaseAdvertisement.push().getKey());
updateAds(id, tuitionimage, providername, providergender);
}
}
});
updateAds()方法编码:-
private boolean updateAds(String id, String tuitionimage, String providername, String providergender) {
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Advertisement").child(id);
Advertisement advertisement = new Advertisement(id, tuitionimage, providername, providergender);
databaseReference.setValue(advertisement);
Toast.makeText(EditAdsActivity.this, "Advertisement has been updated successfully!", Toast.LENGTH_SHORT).show();
return true;
}