gpt4 book ai didi

android - Material DatePicker 在 Fragments 中不起作用

转载 作者:太空宇宙 更新时间:2023-11-03 10:35:29 25 4
gpt4 key购买 nike

使用来自 github 的 compile 'com.wdullaer:materialdatetimepicker:3.0.0' Material design 来支持 android 版本 > 4 的类似设计。

Activity 中,它正在工作。但在 Fragments 中不是。

public class Abs extends AppCompatActivity implements com.wdullaer.materialdatetimepicker.date.DatePickerDialog.OnDateSetListener {

//onCreate method



button.setOnClickListener(new OnClickListener){
//Edittexts
//Edittexts
startActivity(new Intent(Abs.this, Random.class))
}
}



imgdob.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Calendar now = Calendar.getInstance();
DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(Abs.this, now.get(Calendar.YEAR),now.get(Calendar.MONTH), now.get(Calendar.DAY_OF_MONTH));
datePickerDialog.show(getFragmentManager(), "DatePicker");
}
});
}

@Override
public void onDateSet(datePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
edtxdOb.setText(dayOfMonth + "/" + monthOfYear + "/" + year);
}

类似的代码在 fragment 中实现,但我使用了 getActivity()getContext() 而不是 Abs.this 它们没用。

最佳答案

终于找到了解决办法。

 DatePickerDialog datePickerDialog = DatePickerDialog.newInstance(**FragmentClassName**.this,  //Your Fragment Class Name should be here, not getActivity(), or getContex().
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH));
datePickerDialog.show(getActivity().getFragmentManager(), "DatePicker");

关于android - Material DatePicker 在 Fragments 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46469694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com