Android call onClick method without Clicking

前端 未结 4 876
野趣味
野趣味 2021-01-11 21:49

I want to use existing onClick method to make my program simpler. It consists of onClick method and other method:

@Override
public void onClick(View v) {
  s         


        
4条回答
  •  情书的邮戳
    2021-01-11 22:36

    performClick() will play a sound just like if the user clicked on that view, therefore in most cases it's better to use callOnClick(), which will call the OnClickListener without playing any click sound. (Available since API level 15)

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) myView.callOnClick(); //won't play sound
    else myView.performClick(); //will play sound
    

提交回复
热议问题