我不能在Firebase中存储Spinner数据吗?

时间:2019-07-05 14:04:14

标签: android-studio firebase-realtime-database android-spinner

我无法在实时Firebase中存储微调器数据。我可以存储其他数据。假设我有一个数组,我存储一些数据,例如8,9,10,11,12等,并将其连接到微调器,当用户选择其数据时,它将存储数据库。

private void signUpDilog(){

    AlertDialog.Builder alertDialog = new AlertDialog.Builder(MainActivity.this);
    alertDialog.setTitle("Sign Up");
    alertDialog.setMessage("Please fill your information");

    LayoutInflater inflater = this.getLayoutInflater();
    View signUpLayout = inflater.inflate(R.layout.signuplayout,null);

    mfullName = signUpLayout.findViewById(R.id.fullName);
    muserName = signUpLayout.findViewById(R.id.userName);
    mschool = signUpLayout.findViewById(R.id.schoolName);
    mphnNum = signUpLayout.findViewById(R.id.phnNumber);
    memail = signUpLayout.findViewById(R.id.email);
    mpassword = signUpLayout.findViewById(R.id.password);

    mclass = signUpLayout.findViewById(R.id.class_spinner);
    ArrayAdapter<CharSequence> clAdaptar = ArrayAdapter.createFromResource(this,R.array.classArray,android.R.layout.simple_spinner_item);
    clAdaptar.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mclass.setAdapter(clAdaptar);
    mclass.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long l) {
            String item2 = mclass.getSelectedItem().toString();
            Toast.makeText(parent.getContext(),"Selected:"+item2,Toast.LENGTH_SHORT ).show();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });


    alertDialog.setView(signUpLayout);
    alertDialog.setIcon(R.drawable.ic_account_circle_black_24dp);

    alertDialog.setNegativeButton("No", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    });

    alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {

            final SignInUpModel user = new SignInUpModel(mfullName.getText().toString(),muserName.getText().toString(),mschool.getText().toString(),mphnNum.getText().toString(),memail.getText().toString(),mclass.getAdapter().toString(),mpassword.getText().toString());
            users.addListenerForSingleValueEvent(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                    if (dataSnapshot.child(user.getUserName()).exists()){
                        Toast.makeText(MainActivity.this,"User already exists",Toast.LENGTH_LONG).show();
                    }else{
                        users.child(user.getUserName()).setValue(user);
                        Toast.makeText(MainActivity.this,"User registration success!",Toast.LENGTH_LONG).show();
                    }
                }

                @Override
                public void onCancelled(@NonNull DatabaseError databaseError) {

                }
            });
            dialogInterface.dismiss();
        }
    });
    alertDialog.show();



}

这是当前输出: 2 我该怎么办?

0 个答案:

没有答案