在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);
}
}
});
答案 0 :(得分:0)
您应该将addFood(context, breakfastDate, breakfastSearch, 1);
称为onChange
中的datePickerFragment
。
答案 1 :(得分:0)
您可以将以下代码放入您的ngOnInit
中,它会创建OnClickListener
,并且您可以在剩下的代码中得到日期:
DatePickerDialog