[英]Robotium: how to use clickOnButton(<name>) for custom buttons
I am new to Android robotium. 我是Android Robotium的新手。 I am having custom widgets(MyButton, MyTextView, MyCheckBox etc..,) which got inherited from native android widgets.
我有自定义的小部件(MyButton,MyTextView,MyCheckBox等。),这些小部件是从本地android小部件继承的。 How can i add a click event for my custom controls in a robotium script?
如何在Robotium脚本中为自定义控件添加click事件?
I tried using Solo.clickOnButton("Test Button") where the "Test Button" is an instance of MyButton, but i am not getting click event for the Button. 我尝试使用Solo.clickOnButton(“ Test Button”),其中“ Test Button”是MyButton的实例,但是我没有获得Button的click事件。 Any suggestions would be really helpful.
任何建议都会很有帮助。
Thanks, -Ron.. 谢谢-罗恩
I suposse you create the MyButton using extend Button etc etc 我想你使用扩展按钮等创建MyButton
Well to asign click action you should use the normal form. 要指定点击操作,您应该使用常规形式。 For expample
举个例子
main.xml: main.xml:
<com.Ron.MyButton
android:id="@+id/custom_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
In your code you can acces to that button 在您的代码中,您可以访问该按钮
Button myButton = (Button)findViewById(R.id.custom_button);
And then asign onClick action like you do with other normal button: 然后像其他普通按钮一样分配onClick动作:
myButton.setOnclickListener(new onclickListener ....
Other method to asing onClickAction to all views is use int the xml : 将onClickAction赋予所有视图的其他方法是使用xml:
<com.Ron.MyButton
android:id="@+id/custom_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="nameOfMethod"/>
And then in your code: 然后在您的代码中:
public void nameOfMethod (View v){
//code when click the view
}
(This works with all view, linearlayout, imageviews, bustom button .... all ) (这适用于所有视图,线性布局,图像视图,浓淡按钮...。全部)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.