Android - how to find multiple views with common attribute

后端 未结 8 1939
野趣味
野趣味 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:47

    @Override
    protected void onClick(View view){
    switch(view.getId()){
    
    case R.id.whatEverImageViewId :
    //....
    break ;
    
    case R.id.whatEverImageViewId 2 :
    //....
    break ;
    ....
    

    and you can use for loop to add listeners

提交回复
热议问题