Môj kolega a ja som argument. Sme prepočtu aplikácia MVVM+Záväzné. Bolo potrebné spustiť dialógové okno, z fragment. Robím to, ako je tento:
V fragment:
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();
}});
Kolega tiež tvrdí, že potrebujete na to:
V xml súboru napíšeme takto:
android:onClick="@{v -> viewModel.showDialog(context)}"
A v ViewModel:
fun showDialog(context: Context){
AlertDialog.Builder builder = new AlertDialog.Builder(context);
// there's a bunch of code here
alertDialog.show();
}
Prosím, povedzte mi, ktorý z nich je správny?