Poperton
Poperton

Reputation: 1766

How to implement interfaces for dialog created from android binding from a XML?

I have an Android binding for a XML called dialog_volume_all.xml which is a layout. So its binding is called DialogVolumeAllBinding. I'm inflating it like this:

DialogVolumeAllBinding dialogVolumeAllBinding = DialogVolumeAllBinding.inflate(LayoutInflater.from(MainActivity.this));

and I'm creating a dialog from it as

AlertDialog.Builder builder = new AlertDialog.Builder(context, R.style.MyDialogTheme);
AlertDialog alert = builder.create();
alert.setView(dialogVolumeAllBinding);

However I also want to implement public boolean onTouchEvent(MotionEvent event) { on my dialog.

How can I implement things on a dialog from a binding?

Upvotes: 0

Views: 48

Answers (1)

Ravi Kumar
Ravi Kumar

Reputation: 4528

Before setting the view to dialog, create a variable view and initialize it with dialogVolumeAllBinding.root which returns the root view.

View root = dialogVolumeAllBinding.root;

Now you can implement onTouchListener or any other interface on this root view.

root.setOnTouchListener(new OnTouchListener(){ // your code });

Upvotes: 1

Related Questions