如何在 Android 中显式调用 onClick(View v) 方法?是否可以? [英] How to call onClick(View v) method explicitly in an Android? Is it possible?

查看:34
本文介绍了如何在 Android 中显式调用 onClick(View v) 方法?是否可以?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从我的活动的方法 onCreate() 中调用其他类的 onClick(View v).是否可以?

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

因为我在其他类的 onClick 方法中有一个 Popupwindow,所以当方向改变时,我希望我的横向模式的 popupwindow 保持完整并在运行时出现.怎么办?

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?

提前致谢!

推荐答案

假设您要调用的 onClick() 是针对 View x,请使用 x.performClick() 或 x.调用OnClick().在开发人员指南中查看他们的 javadoc 以了解更多详细信息.

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.

请注意,您必须拥有 x 的句柄.如果您的方向发生变化,您应该销毁 PopupWindow 并重新显示它,这应该可以工作.

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.

这篇关于如何在 Android 中显式调用 onClick(View v) 方法?是否可以?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆