我的同事和我发生了争执。 我们的翻译的应用程序。+结合。 有必要开始一个对话从一个片段。 我做这样的:
在该段:
fragmentBinding.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// there's a bunch of code here
alertDialog.show();
}});
同事还说你需要这样做:
在xml文件,我们写如下:
android:onClick="@{v -> viewModel.showDialog(context)}"
和视图模型:
fun showDialog(context: Context){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
// there's a bunch of code here
alertDialog.show();
}
请告诉我哪一个是正确的?