Android - how to find multiple views with common attribute

后端 未结 8 1925
野趣味
野趣味 2020-12-05 02:28

I have a layout with multiple ImageViews, some of those images need to have the same onClickListener. I would like my code to be flexible and to be able to get

8条回答
  •  情书的邮戳
    2020-12-05 02:56

    You can use switch() for multiple widgets.

    switch(viewobject.getId()) {    
     case R.id.imageview1:    
       /* ... */    
       break;    
     case R.id.imageview2:    
       /* ... */      
       break;    
    }
    

提交回复
热议问题