Android - multiple OnClickListener?

前端 未结 5 2297
-上瘾入骨i
-上瘾入骨i 2021-02-20 03:39

I have 4 images. We should be able to click on these images. I\'d like to know if I have to create 4 OnClickListener, or there is another way to do this properly?

5条回答
  •  不要未来只要你来
    2021-02-20 03:42

    You can reuse your listener:

    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
                               public void onClick(DialogInterface dialog, int which) {
                                   /*...*/
                               }
                            });
    
    phone.setOnClickListener(listener);
    bookings.setOnClickListener(listener);
    /*...*/
    

提交回复
热议问题