How to call onClick(View v) method explicitly in an Android? Is it possible?

守給你的承諾、 提交于 2019-11-28 12:42:24

问题


I want to call an onClick(View v) of other class from my activity's method onCreate(). Is it possible?

Because I have a Popupwindow in an onClick method of other class, so when an orientation changes, I want my landscape mode's popupwindow to be intact and appear at runtime. How can it be done?

Thanks in advance!


回答1:


Assuming that the onClick() you want to call is for a View x, use either x.performClick() or x.callOnClick(). Check their javadoc in the Developers Guide for more details.

Notice that you have to have a handle to x. If your orientation changes, you should destroy the PopupWindow and re-display it, which should work.



来源:https://stackoverflow.com/questions/9547299/how-to-call-onclickview-v-method-explicitly-in-an-android-is-it-possible

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!