如何模拟在Android的一个按钮的点击code? [英] How to simulate a button click through code in Android?
问题描述
我怎样才能触发的Android通过code一个按钮单击事件?基本上,我想触发按钮点击编程当一些其它事件发生。
How can I trigger a button click event through code in Android? Basically, I want to trigger the button click programmatically when some other event occurs.
多谢:)
同样的问题,我面对
public void onDateSelectedButtonClick(View v){
/*Something Alarm Management
http://www.java2s.com/Code/Android/Core-Class/Alarmdemo.htm
copied code from this site*/
}
按钮code:
<Button
android:onClick="onDateSelectedButtonClick"
android:text="Set notification for this date" />
不过,我想OnLoadLayout调用该函数没有OnClickEvent 我尝试了很多不同的方式,但我不能没有按钮,单击任何人,请帮助我。
But I want to call that function OnLoadLayout without OnClickEvent I tried a lot of different ways, but I cannot do without button click anybody please help me
推荐答案
还有一个更好的方法。
View.performClick();
<一个href="http://developer.android.com/reference/android/view/View.html#performClick()">http://developer.android.com/reference/android/view/View.html#performClick()
这应该回答所有的问题。每个View继承了这一功能,包括按钮,微调等。
this should answer all your problems. every View inherits this function, including Button, Spinner, etc.
这篇关于如何模拟在Android的一个按钮的点击code?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!