0

What does the following code do in Android

button.setOnClickListner(new View.OnclickListner()){ @override public void onClick(View v){ doSomething() ; } }) ; I have problen understanding the syntax of the papamter that is sent to the setOnClickListner function.

6th May 2018, 4:37 PM
test
2 Respostas
+ 1
Thanks, But what's the type of the argument to setOnClickListner? What is the new statement creating? Edit: { After installing Android Studio and checking out the types, it seems the "new" statement is creating an instance of an anonymous class of type: Interface View.OnClickListner and overrides the OnClick method. } // It seems like I can't comment on your answer!
6th May 2018, 6:01 PM
test
0
onClickListener is used to listen the events of a particular input device i.e mouse or keyboard ..like mousePressed,keyPressed etc.. onClick is a method which u override to ur needs accordingly i.e what action has to be performed when u click on a button i.e tap a button ..doSomething is a method u r calling which is the code supposed to work when u click the button
6th May 2018, 5:49 PM
Suhail Pappu
Suhail Pappu - avatar