代码保持运行而没有正确的输入顺序

时间:2019-01-14 11:48:47

标签: javascript android

OnClickListener中,addFood需要从日期选择器片段中输入日期和时间。

我如何让它等到用户完成输入?

Button breakfastAdd = findViewById(R.id.breakFastButton);
    breakfastAdd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (breakfastSearch.getCount() == 0) {
                LayoutInflater inflater = getLayoutInflater();
                View layout = inflater.inflate(R.layout.toast,
                        (ViewGroup) findViewById(R.id.emptySelectionLayout));

                TextView text = layout.findViewById(R.id.toastText);
                text.setText(R.string.selectedIsEmpty);
                Toast toast = new Toast(getApplicationContext());
                toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                toast.setDuration(Toast.LENGTH_LONG);
                toast.setView(layout);
                toast.show();
                Log.d("list is", "empty");

            } else {
                new datePickerFragment().show(getSupportFragmentManager(), "datePicker");

                addFood(context, breakfastDate, breakfastSearch, 1);
            }

        }

    });

2 个答案:

答案 0 :(得分:0)

您应该将addFood(context, breakfastDate, breakfastSearch, 1);称为onChange中的datePickerFragment

答案 1 :(得分:0)

您可以将以下代码放入您的ngOnInit中,它会创建OnClickListener,并且您可以在剩下的代码中得到日期:

DatePickerDialog