Java 微调器选定值为';t正在上载到firebase数据库

Java 微调器选定值为';t正在上载到firebase数据库,java,android,firebase,Java,Android,Firebase,我正在制作一个购物应用程序,我想将微调器的选定值上传到我的数据库。该值正在上载到数据库,但上载的值不正确。这是我的密码 mySpinner = (Spinner) findViewById(R.id.spinner1); ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_li

我正在制作一个购物应用程序,我想将微调器的选定值上传到我的数据库。该值正在上载到数据库,但上载的值不正确。这是我的密码

mySpinner = (Spinner) findViewById(R.id.spinner1);


    ArrayAdapter<String> myAdapter = new ArrayAdapter<String>(getApplicationContext(),
            android.R.layout.simple_list_item_1, getResources().getStringArray(R.array.names));
    myAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mySpinner.setAdapter(myAdapter);
    selectedValue = mySpinner.getSelectedItem().toString();
mySpinner=(微调器)findviewbyd(R.id.spinner1);
ArrayAdapter myAdapter=新的ArrayAdapter(getApplicationContext(),
android.R.layout.simple_list_item_1,getResources().getStringArray(R.array.names));
myAdapter.setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
setAdapter(myAdapter);
selectedValue=mySpinner.getSelectedItem().toString();

private void addingToCartList()
{
字符串saveCurrentTime,saveCurrentDate;
Calendar calForDate=Calendar.getInstance();
SimpleDataFormat currentDate=新的SimpleDataFormat(“MMM dd,yyyy”);
saveCurrentDate=currentDate.format(calForDate.getTime());
SimpleDataFormat currentTime=新的SimpleDataFormat(“HH:mm:ss a”);
saveCurrentTime=currentTime.format(calForDate.getTime());
final DatabaseReference cartListRef=FirebaseDatabase.getInstance().getReference().child(“购物车列表”);
final HashMap cartMap=新HashMap();
cartMap.put(“pid”,productID);
cartMap.put(“pname”,productName.getText().toString());
cartMap.put(“price”,productPrice.getText().toString());
cartMap.put(“日期”,saveCurrentDate);
cartMap.put(“时间”,saveCurrentTime);
cartMap.put(“数量”,selectedValue);
cartMap.put(“折扣”,“折扣”);
cartListRef.child(“用户视图”).child(Prevelant.currentOnlineUser.getUsername())
.child(“产品”).child(产品ID)
.updateChildren(cartMap)
.addOnCompleteListener(新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务)
{
if(task.issusccessful())
{
cartListRef.child(“管理视图”).child(Prevelant.currentOnlineUser.getUsername())
.child(“产品”).child(产品ID)
.updateChildren(cartMap)
.addOnCompleteListener(新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务)
{
if(task.issusccessful())
{
Toast.makeText(ProductDetails2Activity.this,“添加到购物车列表”,Toast.LENGTH_SHORT.show();
意向意向=新意向(ProductDetails2Activity.this、CartActivity.class);
星触觉(意向);
}
}
});
}
}
});
}

每次上传到数据库的值都是250


我想解决的是…

在我看来,您应该在用户单击“提交”后获取所选项目,但您甚至在用户更改该项目之前就已经获取了该值,因此默认情况下,它将获取第一个项目

private void addingToCartList()
{
String saveCurrentTime, saveCurrentDate;

Calendar calForDate = Calendar.getInstance();
SimpleDateFormat currentDate = new SimpleDateFormat("MMM dd, yyyy");
saveCurrentDate = currentDate.format(calForDate.getTime());
SimpleDateFormat currentTime = new SimpleDateFormat("HH:mm:ss a");
saveCurrentTime = currentTime.format(calForDate.getTime());

//putting spinner here
selectedValue = mySpinner.getSelectedItem().toString();

final DatabaseReference cartListRef = FirebaseDatabase.getInstance().getReference().child("Cart List");

final HashMap<String, Object> cartMap = new HashMap<>();
cartMap.put("pid", productID);
cartMap.put("pname", productName.getText().toString());
cartMap.put("price", productPrice.getText().toString());
cartMap.put("date", saveCurrentDate);
cartMap.put("time", saveCurrentTime);
cartMap.put("quantity", selectedValue);
cartMap.put("discount", "");
cartListRef.child("User View").child(Prevelant.currentOnlineUser.getUsername())
        .child("Products").child(productID)
        .updateChildren(cartMap)
        .addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task)
            {
                if(task.isSuccessful())
                {
                    cartListRef.child("Admin View").child(Prevelant.currentOnlineUser.getUsername())
                            .child("Products").child(productID)
                            .updateChildren(cartMap)
                            .addOnCompleteListener(new OnCompleteListener<Void>() {
                                @Override
                                public void onComplete(@NonNull Task<Void> task)
                                {
                                    if(task.isSuccessful())
                                    {
                                        Toast.makeText(ProductDetails2Activity.this, "Added to Cart List", Toast.LENGTH_SHORT).show();
                                        Intent intent = new Intent (ProductDetails2Activity.this, CartActivity.class);
                                        startActivity(intent);
                                    }
                                }
                            });
                }
            }
        });
}
private void addingToCartList()
{
字符串saveCurrentTime,saveCurrentDate;
Calendar calForDate=Calendar.getInstance();
SimpleDataFormat currentDate=新的SimpleDataFormat(“MMM dd,yyyy”);
saveCurrentDate=currentDate.format(calForDate.getTime());
SimpleDataFormat currentTime=新的SimpleDataFormat(“HH:mm:ss a”);
saveCurrentTime=currentTime.format(calForDate.getTime());
//把纺纱机放在这里
selectedValue=mySpinner.getSelectedItem().toString();
final DatabaseReference cartListRef=FirebaseDatabase.getInstance().getReference().child(“购物车列表”);
final HashMap cartMap=新HashMap();
cartMap.put(“pid”,productID);
cartMap.put(“pname”,productName.getText().toString());
cartMap.put(“price”,productPrice.getText().toString());
cartMap.put(“日期”,saveCurrentDate);
cartMap.put(“时间”,saveCurrentTime);
cartMap.put(“数量”,selectedValue);
cartMap.put(“折扣”,“折扣”);
cartListRef.child(“用户视图”).child(Prevelant.currentOnlineUser.getUsername())
.child(“产品”).child(产品ID)
.updateChildren(cartMap)
.addOnCompleteListener(新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务)
{
if(task.issusccessful())
{
cartListRef.child(“管理视图”).child(Prevelant.currentOnlineUser.getUsername())
.child(“产品”).child(产品ID)
.updateChildren(cartMap)
.addOnCompleteListener(新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务)
{
if(task.issusccessful())
{
Toast.makeText(ProductDetails2Activity.this,“添加到购物车列表”,Toast.LENGTH_SHORT.show();
意向意向=新意向(ProductDetails2Activity.this、CartActivity.class);
星触觉(意向);
}
}
});
}
}
});
}
我希望这能奏效 让我知道它是否有效

private void addingToCartList()
{
String saveCurrentTime, saveCurrentDate;

Calendar calForDate = Calendar.getInstance();
SimpleDateFormat currentDate = new SimpleDateFormat("MMM dd, yyyy");
saveCurrentDate = currentDate.format(calForDate.getTime());
SimpleDateFormat currentTime = new SimpleDateFormat("HH:mm:ss a");
saveCurrentTime = currentTime.format(calForDate.getTime());

//putting spinner here
selectedValue = mySpinner.getSelectedItem().toString();

final DatabaseReference cartListRef = FirebaseDatabase.getInstance().getReference().child("Cart List");

final HashMap<String, Object> cartMap = new HashMap<>();
cartMap.put("pid", productID);
cartMap.put("pname", productName.getText().toString());
cartMap.put("price", productPrice.getText().toString());
cartMap.put("date", saveCurrentDate);
cartMap.put("time", saveCurrentTime);
cartMap.put("quantity", selectedValue);
cartMap.put("discount", "");
cartListRef.child("User View").child(Prevelant.currentOnlineUser.getUsername())
        .child("Products").child(productID)
        .updateChildren(cartMap)
        .addOnCompleteListener(new OnCompleteListener<Void>() {
            @Override
            public void onComplete(@NonNull Task<Void> task)
            {
                if(task.isSuccessful())
                {
                    cartListRef.child("Admin View").child(Prevelant.currentOnlineUser.getUsername())
                            .child("Products").child(productID)
                            .updateChildren(cartMap)
                            .addOnCompleteListener(new OnCompleteListener<Void>() {
                                @Override
                                public void onComplete(@NonNull Task<Void> task)
                                {
                                    if(task.isSuccessful())
                                    {
                                        Toast.makeText(ProductDetails2Activity.this, "Added to Cart List", Toast.LENGTH_SHORT).show();
                                        Intent intent = new Intent (ProductDetails2Activity.this, CartActivity.class);
                                        startActivity(intent);
                                    }
                                }
                            });
                }
            }
        });
}