Jaison Joseph
Jaison Joseph

Reputation: 133

How to pass string value to DatabaseReference android

I want to display the value entered in Alert Dialog box to to fire base database, but i am not sure how to do that. Fire-base database is working properly , but i dont know how to pass the value from text field to myref

         android.R.drawable.ic_dialog_dialer).setView(
                    layout).setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Dialog dialog = (Dialog) dialogInterface;



                    EditText inputLocation = (EditText) dialog.findViewById(R.id.dialog_et_location);


                    if (inputLocation.getText().toString().isEmpty()){
                        return;
                    }




                    mTextAddress.setText(inputLocation.getText().toString());

                 //   String bbb = inputLocation.getText().toString();




                    FirebaseDatabase database = FirebaseDatabase.getInstance();
                    DatabaseReference myref = database.getReference("message");

            //i want to save inputLocation value to my ref please help me

                   // inputLocation.setText(abc);

                   // mTextEditAddress.setText(abc);












                }
            })

Upvotes: 0

Views: 291

Answers (1)

Yogev Uzan
Yogev Uzan

Reputation: 81

Assuming your "message" reference doesn't have any child in it, it would look like this:

String inputLocation = inputLocation.getText().toString(); 

FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myref = database.getReference("message");
myref.setValue("inputLocation", inputLocation);

Upvotes: 1

Related Questions