Using Switch Statement to Handle Button Clicks

后端 未结 7 982
梦毁少年i
梦毁少年i 2020-12-05 03:15

I\'m trying to wrap my head around Views, Listeners etc. I have an Activity with 2 Buttons: buttonplay and buttonstop. My problem is I can\'t wrap my head around the Views

7条回答
  •  再見小時候
    2020-12-05 03:55

    I use Butterknife with switch-case to handle this kind of cases:

        @OnClick({R.id.button_bireysel, R.id.button_kurumsal})
            public void onViewClicked(View view) {
                switch (view.getId()) {
    
    
                    case R.id.button_bireysel:
     //Do something
    
                        break;
                    case R.id.button_kurumsal:
    
         //Do something
    
                        break;
    
                }
            }
    

    But the thing is there is no default case and switch statement falls through

提交回复
热议问题