What does it mean that a Listener can be replaced with lambda?

前端 未结 3 1822
一个人的身影
一个人的身影 2020-12-25 09:11

I have implemented an AlertDialog with normal negative and positive button click listeners.

When I called new DialogInterface.OnClickListener()

3条回答
  •  甜味超标
    2020-12-25 10:06

    To replace the classic new DialogInterface.OnClickListener() implementation with lambda expression is enough with the following

     builder.setPositiveButton("resourceId", ((DialogInterface dialog, int which) -> {
          // do something here
     }));
    

    It´s just taking the onClick event parameters.

提交回复
热议问题