2021年1月27日星期三

how can i add data from spinner to specific firebase database tables' key?

I create spinner and i want to store what i select inenter image description here real-time database , but when i did this the data from spinner create new child and store data in it

I want the data from spinner store in same child that i give it to firebase

I searched too much to solve this problem but i didn't found sol can help me pls , and thx in advance

  ArrayAdapter arrayAdapter = new ArrayAdapter(this              ,android.R.layout.simple_spinner_dropdown_item,positions);      arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);      spinner.setAdapter(arrayAdapter);        sendData.setOnClickListener(new View.OnClickListener() {          @Override          public void onClick(View view) {                final ProgressDialog mDialog = new ProgressDialog(Nomination.this);              mDialog.setMessage("Please waiting");              mDialog.show();                if (name.length()==0){                  mDialog.dismiss();                  name.setError("Enter your name");              }else if (Id.length()==0){                  mDialog.dismiss();                  Id.setError("Enter your ID");              }else{                  databaseReference.addValueEventListener(new ValueEventListener() {                      @Override                      public void onDataChange(@NonNull DataSnapshot snapshot) {                          //cheack by ID if condidate is already exist                            if (snapshot.child(Id.getText().toString()).exists())                          {                              mDialog.dismiss();                              Toast.makeText(Nomination.this, "انت مرشح", Toast.LENGTH_LONG).show();                          }                          else                          {                              mDialog.dismiss();                              Condidate condidate = new Condidate(name.getText().toString());                              databaseReference.child(Id.getText().toString()).setValue(condidate);                              finish();                          }                        }                        @Override                      public void onCancelled(@NonNull DatabaseError error) {                        }                  });              }                saveValue(item);              }      });    }    @Override  public void onItemSelected(AdapterView <?> adapterView, View view, int i, long l) {      item= spinner.getSelectedItem().toString();  }    @Override  public void onNothingSelected(AdapterView <?> adapterView) {    }    void saveValue(String item){      if (item == "اختار المنصب"){          Toast.makeText(this, "اختار منصب الترشح", Toast.LENGTH_LONG).show();      }else {          p.setPostion(item);          String id = databaseReference.push().getKey();          databaseReference.child(id).setValue(p);          Toast.makeText(this, "تم الترشح", Toast.LENGTH_SHORT).show();      }  }  
https://stackoverflow.com/questions/65930059/how-can-i-add-data-from-spinner-to-specific-firebase-database-tables-key January 28, 2021 at 10:08AM

没有评论:

发表评论