How to edit a child value when under a firebase auto generated key Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experience Should we burninate the [wrap] tag?How to use SharedPreferences in Android to store, fetch and edit valuesgeneric listener for buttons in a layout of android?I am trying to set alarm on specific time using alarm manager but alarm initiated instantly?Why does ListActivity not display last item in ArrayAdapter?get around of error 'can not resolve symbol'Saving ToggleButton state in ListView by using SharedPreferencesAdding Social Media Share Logic From Firebase in AndroidSearch Firestore query don't show data in RecycleViewCloud Firestore Security Rules permissionHow to add child(Product) under a child(Store) in Firebase Database using RecyclerView

How does a Death Domain cleric's Touch of Death feature work with Touch-range spells delivered by familiars?

Is a manifold-with-boundary with given interior and non-empty boundary essentially unique?

What LEGO pieces have "real-world" functionality?

Is it true that "carbohydrates are of no use for the basal metabolic need"?

How to deal with a team lead who never gives me credit?

Stars Make Stars

Is the Standard Deduction better than Itemized when both are the same amount?

Output the ŋarâþ crîþ alphabet song without using (m)any letters

Letter Boxed validator

Are my PIs rude or am I just being too sensitive?

Storing hydrofluoric acid before the invention of plastics

Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?

Why is "Consequences inflicted." not a sentence?

What are the pros and cons of Aerospike nosecones?

What does the "x" in "x86" represent?

Is there a Spanish version of "dot your i's and cross your t's" that includes the letter 'ñ'?

What makes black pepper strong or mild?

How widely used is the term Treppenwitz? Is it something that most Germans know?

Why aren't air breathing engines used as small first stages

Did Xerox really develop the first LAN?

What are 'alternative tunings' of a guitar and why would you use them? Doesn't it make it more difficult to play?

Can Pao de Queijo, and similar foods, be kosher for Passover?

Why is black pepper both grey and black?

How do I stop a creek from eroding my steep embankment?



How to edit a child value when under a firebase auto generated key



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
The Ask Question Wizard is Live!
Data science time! April 2019 and salary with experience
Should we burninate the [wrap] tag?How to use SharedPreferences in Android to store, fetch and edit valuesgeneric listener for buttons in a layout of android?I am trying to set alarm on specific time using alarm manager but alarm initiated instantly?Why does ListActivity not display last item in ArrayAdapter?get around of error 'can not resolve symbol'Saving ToggleButton state in ListView by using SharedPreferencesAdding Social Media Share Logic From Firebase in AndroidSearch Firestore query don't show data in RecycleViewCloud Firestore Security Rules permissionHow to add child(Product) under a child(Store) in Firebase Database using RecyclerView



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I am trying to edit the value of "shopB" in my database. I am doing so inside of a view holder, by use of a dialog box with an edit text field and an approve button. When a user clicks on a specific transaction, they're given a dialog box where they enter the value for shopB and then click Approve.



I am struggling to do this as I cannot access that value because of the uniquely generated key that firebase has. I have many posts with similar problems to mine but as I am doing this inside of a view holder I do not see how I can use DataSnapshot. Any help would be greatly appreciated as I am getting very lost.



Database Structure:
enter image description here



viewHolder.setItemClickListener(new ItemClickListener() 
@Override
public void onClick(android.view.View view, int position, boolean isLongClick)
Toast.makeText(Request.this, "Receiving: " + shopA, Toast.LENGTH_SHORT).show();
ThisDialog = new Dialog(Request.this);
ThisDialog.setContentView(R.layout.dialog_template);
final EditText Write = (EditText) ThisDialog.findViewById((R.id.write));
Button Approve = (Button) ThisDialog.findViewById(R.id.approve);

Write.setEnabled(true);
Approve.setEnabled(true);

Approve.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
String newShopB = Write.getText().toString().replace(".", " ");
transaction.child("key").child("shopB").setValue(newShopB);
Toast.makeText(Request.this, "CustB Approval", Toast.LENGTH_SHORT).show();
ThisDialog.cancel();

);
ThisDialog.show();

);


This would be my code but obviously where I have "transaction.child("key")" does not find the key.



Oh and transaction is defined earlier in my code as



database = FirebaseDatabase.getInstance();
start = database.getReference("Transaction");
transaction = start.child(passedEmail);









share|improve this question
























  • I think that might want to rethink your database structure. If you don't know the key, you simply won't be able to retrieve the values. For what I guess cloe@ test may have multiple transactions, if you want to keep the auto generated id's maybe after you set the value, you could get the key and store it in another "pending" node, so you can have access to the id's of all your "pending" transactions. Just an idea out of guessing for lack of context of what you are trying to achieve.

    – Racu
    Mar 9 at 8:42






  • 1





    Thank you @Racu, I used your idea to solve my issue. As a quick work around I stored the unique key with the rest of the transaction data on transaction creation. I figure this wouldn't be an ideal solution as I would imagine there would be security issues regarding this. But this does not bother me for now as it is just for a college project which I am out of time on so for now I am happy with this as a solution and it makes my key very easily accessible for me when needed.

    – C.Gibbons
    Mar 9 at 16:14

















0















I am trying to edit the value of "shopB" in my database. I am doing so inside of a view holder, by use of a dialog box with an edit text field and an approve button. When a user clicks on a specific transaction, they're given a dialog box where they enter the value for shopB and then click Approve.



I am struggling to do this as I cannot access that value because of the uniquely generated key that firebase has. I have many posts with similar problems to mine but as I am doing this inside of a view holder I do not see how I can use DataSnapshot. Any help would be greatly appreciated as I am getting very lost.



Database Structure:
enter image description here



viewHolder.setItemClickListener(new ItemClickListener() 
@Override
public void onClick(android.view.View view, int position, boolean isLongClick)
Toast.makeText(Request.this, "Receiving: " + shopA, Toast.LENGTH_SHORT).show();
ThisDialog = new Dialog(Request.this);
ThisDialog.setContentView(R.layout.dialog_template);
final EditText Write = (EditText) ThisDialog.findViewById((R.id.write));
Button Approve = (Button) ThisDialog.findViewById(R.id.approve);

Write.setEnabled(true);
Approve.setEnabled(true);

Approve.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
String newShopB = Write.getText().toString().replace(".", " ");
transaction.child("key").child("shopB").setValue(newShopB);
Toast.makeText(Request.this, "CustB Approval", Toast.LENGTH_SHORT).show();
ThisDialog.cancel();

);
ThisDialog.show();

);


This would be my code but obviously where I have "transaction.child("key")" does not find the key.



Oh and transaction is defined earlier in my code as



database = FirebaseDatabase.getInstance();
start = database.getReference("Transaction");
transaction = start.child(passedEmail);









share|improve this question
























  • I think that might want to rethink your database structure. If you don't know the key, you simply won't be able to retrieve the values. For what I guess cloe@ test may have multiple transactions, if you want to keep the auto generated id's maybe after you set the value, you could get the key and store it in another "pending" node, so you can have access to the id's of all your "pending" transactions. Just an idea out of guessing for lack of context of what you are trying to achieve.

    – Racu
    Mar 9 at 8:42






  • 1





    Thank you @Racu, I used your idea to solve my issue. As a quick work around I stored the unique key with the rest of the transaction data on transaction creation. I figure this wouldn't be an ideal solution as I would imagine there would be security issues regarding this. But this does not bother me for now as it is just for a college project which I am out of time on so for now I am happy with this as a solution and it makes my key very easily accessible for me when needed.

    – C.Gibbons
    Mar 9 at 16:14













0












0








0








I am trying to edit the value of "shopB" in my database. I am doing so inside of a view holder, by use of a dialog box with an edit text field and an approve button. When a user clicks on a specific transaction, they're given a dialog box where they enter the value for shopB and then click Approve.



I am struggling to do this as I cannot access that value because of the uniquely generated key that firebase has. I have many posts with similar problems to mine but as I am doing this inside of a view holder I do not see how I can use DataSnapshot. Any help would be greatly appreciated as I am getting very lost.



Database Structure:
enter image description here



viewHolder.setItemClickListener(new ItemClickListener() 
@Override
public void onClick(android.view.View view, int position, boolean isLongClick)
Toast.makeText(Request.this, "Receiving: " + shopA, Toast.LENGTH_SHORT).show();
ThisDialog = new Dialog(Request.this);
ThisDialog.setContentView(R.layout.dialog_template);
final EditText Write = (EditText) ThisDialog.findViewById((R.id.write));
Button Approve = (Button) ThisDialog.findViewById(R.id.approve);

Write.setEnabled(true);
Approve.setEnabled(true);

Approve.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
String newShopB = Write.getText().toString().replace(".", " ");
transaction.child("key").child("shopB").setValue(newShopB);
Toast.makeText(Request.this, "CustB Approval", Toast.LENGTH_SHORT).show();
ThisDialog.cancel();

);
ThisDialog.show();

);


This would be my code but obviously where I have "transaction.child("key")" does not find the key.



Oh and transaction is defined earlier in my code as



database = FirebaseDatabase.getInstance();
start = database.getReference("Transaction");
transaction = start.child(passedEmail);









share|improve this question
















I am trying to edit the value of "shopB" in my database. I am doing so inside of a view holder, by use of a dialog box with an edit text field and an approve button. When a user clicks on a specific transaction, they're given a dialog box where they enter the value for shopB and then click Approve.



I am struggling to do this as I cannot access that value because of the uniquely generated key that firebase has. I have many posts with similar problems to mine but as I am doing this inside of a view holder I do not see how I can use DataSnapshot. Any help would be greatly appreciated as I am getting very lost.



Database Structure:
enter image description here



viewHolder.setItemClickListener(new ItemClickListener() 
@Override
public void onClick(android.view.View view, int position, boolean isLongClick)
Toast.makeText(Request.this, "Receiving: " + shopA, Toast.LENGTH_SHORT).show();
ThisDialog = new Dialog(Request.this);
ThisDialog.setContentView(R.layout.dialog_template);
final EditText Write = (EditText) ThisDialog.findViewById((R.id.write));
Button Approve = (Button) ThisDialog.findViewById(R.id.approve);

Write.setEnabled(true);
Approve.setEnabled(true);

Approve.setOnClickListener(new View.OnClickListener()
@Override
public void onClick(View v)
String newShopB = Write.getText().toString().replace(".", " ");
transaction.child("key").child("shopB").setValue(newShopB);
Toast.makeText(Request.this, "CustB Approval", Toast.LENGTH_SHORT).show();
ThisDialog.cancel();

);
ThisDialog.show();

);


This would be my code but obviously where I have "transaction.child("key")" does not find the key.



Oh and transaction is defined earlier in my code as



database = FirebaseDatabase.getInstance();
start = database.getReference("Transaction");
transaction = start.child(passedEmail);






java android firebase firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 20:50









Fire-In-D-Hole

387112




387112










asked Mar 8 at 16:27









C.GibbonsC.Gibbons

64




64












  • I think that might want to rethink your database structure. If you don't know the key, you simply won't be able to retrieve the values. For what I guess cloe@ test may have multiple transactions, if you want to keep the auto generated id's maybe after you set the value, you could get the key and store it in another "pending" node, so you can have access to the id's of all your "pending" transactions. Just an idea out of guessing for lack of context of what you are trying to achieve.

    – Racu
    Mar 9 at 8:42






  • 1





    Thank you @Racu, I used your idea to solve my issue. As a quick work around I stored the unique key with the rest of the transaction data on transaction creation. I figure this wouldn't be an ideal solution as I would imagine there would be security issues regarding this. But this does not bother me for now as it is just for a college project which I am out of time on so for now I am happy with this as a solution and it makes my key very easily accessible for me when needed.

    – C.Gibbons
    Mar 9 at 16:14

















  • I think that might want to rethink your database structure. If you don't know the key, you simply won't be able to retrieve the values. For what I guess cloe@ test may have multiple transactions, if you want to keep the auto generated id's maybe after you set the value, you could get the key and store it in another "pending" node, so you can have access to the id's of all your "pending" transactions. Just an idea out of guessing for lack of context of what you are trying to achieve.

    – Racu
    Mar 9 at 8:42






  • 1





    Thank you @Racu, I used your idea to solve my issue. As a quick work around I stored the unique key with the rest of the transaction data on transaction creation. I figure this wouldn't be an ideal solution as I would imagine there would be security issues regarding this. But this does not bother me for now as it is just for a college project which I am out of time on so for now I am happy with this as a solution and it makes my key very easily accessible for me when needed.

    – C.Gibbons
    Mar 9 at 16:14
















I think that might want to rethink your database structure. If you don't know the key, you simply won't be able to retrieve the values. For what I guess cloe@ test may have multiple transactions, if you want to keep the auto generated id's maybe after you set the value, you could get the key and store it in another "pending" node, so you can have access to the id's of all your "pending" transactions. Just an idea out of guessing for lack of context of what you are trying to achieve.

– Racu
Mar 9 at 8:42





I think that might want to rethink your database structure. If you don't know the key, you simply won't be able to retrieve the values. For what I guess cloe@ test may have multiple transactions, if you want to keep the auto generated id's maybe after you set the value, you could get the key and store it in another "pending" node, so you can have access to the id's of all your "pending" transactions. Just an idea out of guessing for lack of context of what you are trying to achieve.

– Racu
Mar 9 at 8:42




1




1





Thank you @Racu, I used your idea to solve my issue. As a quick work around I stored the unique key with the rest of the transaction data on transaction creation. I figure this wouldn't be an ideal solution as I would imagine there would be security issues regarding this. But this does not bother me for now as it is just for a college project which I am out of time on so for now I am happy with this as a solution and it makes my key very easily accessible for me when needed.

– C.Gibbons
Mar 9 at 16:14





Thank you @Racu, I used your idea to solve my issue. As a quick work around I stored the unique key with the rest of the transaction data on transaction creation. I figure this wouldn't be an ideal solution as I would imagine there would be security issues regarding this. But this does not bother me for now as it is just for a college project which I am out of time on so for now I am happy with this as a solution and it makes my key very easily accessible for me when needed.

– C.Gibbons
Mar 9 at 16:14












1 Answer
1






active

oldest

votes


















0














Here's a possible solution to workaround on your project:



start.addListenerForSingleValueEvent(new ValueEventListener() 
@Override
public void onDataChange(DataSnapshot dataSnapshot)
for (DataSnapshot child : dataSnapshot.child(key).getChildren())

//insert additional codes here


);





share|improve this answer























  • I don't understand your solution. I believe I understand what it does but I don't see how this solves my problem, or helps. My problem is referencing that "key" I don't know how to access/reference it. And therefore I don't know how to set the value of "shopB" in my database.

    – C.Gibbons
    Mar 8 at 17:32











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55067201%2fhow-to-edit-a-child-value-when-under-a-firebase-auto-generated-key%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Here's a possible solution to workaround on your project:



start.addListenerForSingleValueEvent(new ValueEventListener() 
@Override
public void onDataChange(DataSnapshot dataSnapshot)
for (DataSnapshot child : dataSnapshot.child(key).getChildren())

//insert additional codes here


);





share|improve this answer























  • I don't understand your solution. I believe I understand what it does but I don't see how this solves my problem, or helps. My problem is referencing that "key" I don't know how to access/reference it. And therefore I don't know how to set the value of "shopB" in my database.

    – C.Gibbons
    Mar 8 at 17:32















0














Here's a possible solution to workaround on your project:



start.addListenerForSingleValueEvent(new ValueEventListener() 
@Override
public void onDataChange(DataSnapshot dataSnapshot)
for (DataSnapshot child : dataSnapshot.child(key).getChildren())

//insert additional codes here


);





share|improve this answer























  • I don't understand your solution. I believe I understand what it does but I don't see how this solves my problem, or helps. My problem is referencing that "key" I don't know how to access/reference it. And therefore I don't know how to set the value of "shopB" in my database.

    – C.Gibbons
    Mar 8 at 17:32













0












0








0







Here's a possible solution to workaround on your project:



start.addListenerForSingleValueEvent(new ValueEventListener() 
@Override
public void onDataChange(DataSnapshot dataSnapshot)
for (DataSnapshot child : dataSnapshot.child(key).getChildren())

//insert additional codes here


);





share|improve this answer













Here's a possible solution to workaround on your project:



start.addListenerForSingleValueEvent(new ValueEventListener() 
@Override
public void onDataChange(DataSnapshot dataSnapshot)
for (DataSnapshot child : dataSnapshot.child(key).getChildren())

//insert additional codes here


);






share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 8 at 17:08









Rica Mae MonteverdeRica Mae Monteverde

562




562












  • I don't understand your solution. I believe I understand what it does but I don't see how this solves my problem, or helps. My problem is referencing that "key" I don't know how to access/reference it. And therefore I don't know how to set the value of "shopB" in my database.

    – C.Gibbons
    Mar 8 at 17:32

















  • I don't understand your solution. I believe I understand what it does but I don't see how this solves my problem, or helps. My problem is referencing that "key" I don't know how to access/reference it. And therefore I don't know how to set the value of "shopB" in my database.

    – C.Gibbons
    Mar 8 at 17:32
















I don't understand your solution. I believe I understand what it does but I don't see how this solves my problem, or helps. My problem is referencing that "key" I don't know how to access/reference it. And therefore I don't know how to set the value of "shopB" in my database.

– C.Gibbons
Mar 8 at 17:32





I don't understand your solution. I believe I understand what it does but I don't see how this solves my problem, or helps. My problem is referencing that "key" I don't know how to access/reference it. And therefore I don't know how to set the value of "shopB" in my database.

– C.Gibbons
Mar 8 at 17:32



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55067201%2fhow-to-edit-a-child-value-when-under-a-firebase-auto-generated-key%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

1928 у кіно

Захаров Федір Захарович

Ель Греко