转换Spinner& Datepickers选择值作为字符串并保存到firebase

时间:2016-12-14 13:47:37

标签: android datepicker spinner

亲们,我有一个酒店预订表格,有两个日期选择器和三个微调器来收集用户数据(签到,结账,房间,成人,儿童)......我试图将表格数据保存到我的火力架,代码工作正常但我在我的数据库上得到了非常奇怪的数据,我一定错过了字符串转换的东西..这里是数据库中的记录

成年人: “android.support.v7.widget.AppCompatSpinner {e09c ...”

签: “android.widget.DatePicker {14eadf8e V.E ..... ......”

结帐: “android.widget.DatePicker {194a02de V.E ..... ......”

儿童: “android.support.v7.widget.AppCompatSpinner {1dba ...”

间: “android.support.v7.widget.AppCompatSpinner {D413 ......”

我的BookingActivity如下

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_booking_form);
        Firebase.setAndroidContext(this);
        reserve = (Button) findViewById(R.id.reserve);
        spinner1 = (Spinner) findViewById(R.id.spinner1);
        spinner2 = (Spinner) findViewById(R.id.spinner2);
        spinner3 = (Spinner) findViewById(R.id.spinner3);
        datePicker0 = (DatePicker) findViewById(R.id.datePicker0);
        datePicker2 = (DatePicker) findViewById(R.id.datePicker2);






        reserve.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //Creating firebase object
                final Firebase ref = new Firebase("https://ngong-hills.firebaseio.com/");

                //Getting values to store

                String Checkin = datePicker0.toString().trim();
                String Checkout = datePicker2.toString().trim();
                String rooms = spinner1.toString().trim();
                String adults = spinner2.toString().trim();
                String children = spinner3.toString().trim();

                Booking booking = new Booking();
                booking.setadults(adults);
                booking.setchildren(children);
                booking.setrooms(rooms);
                booking.setCheckout(Checkout);
                booking.setCheckin(Checkin);

                Firebase newRef = ref.child("Bookings").push();
                newRef.setValue(booking);


            }
        });

    }

    @Override
    public void onClick(View view) {

        if(view == reserve){
            //open login activity when user taps on the already registered textview
            startActivity(new Intent(this, HomeNav.class));
        }

    }

我不知道我错过了什么  ..

1 个答案:

答案 0 :(得分:0)

driver.find_element_by_tag_name('body').send_keys(Keys.PAGE_DOWN)

您实际上通过toString方法获取整个视图元素(Spinner,DatePicker)字符串表示形式。而是试图这样做,得到像这样的Spinner值,

String Checkin = datePicker0.toString().trim();
String Checkout = datePicker2.toString().trim();
String rooms = spinner1.toString().trim();
String adults = spinner2.toString().trim();
String children = spinner3.toString().trim();

为其余的Spinners做同样的事情。 Here is how您可以从DatePicker获取日期值并将其转换为String。