[英]Robotium: how to use clickOnButton(<name>) for custom buttons
我是Android Robotium的新手。 我有自定义的小部件(MyButton,MyTextView,MyCheckBox等。),这些小部件是从本地android小部件继承的。 如何在Robotium脚本中为自定义控件添加click事件?
我尝试使用Solo.clickOnButton(“ Test Button”),其中“ Test Button”是MyButton的实例,但是我没有获得Button的click事件。 任何建议都会很有帮助。
谢谢-罗恩
我想你使用扩展按钮等创建MyButton
要指定点击操作,您应该使用常规形式。 举个例子
main.xml:
<com.Ron.MyButton
android:id="@+id/custom_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
在您的代码中,您可以访问该按钮
Button myButton = (Button)findViewById(R.id.custom_button);
然后像其他普通按钮一样分配onClick动作:
myButton.setOnclickListener(new onclickListener ....
将onClickAction赋予所有视图的其他方法是使用xml:
<com.Ron.MyButton
android:id="@+id/custom_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="nameOfMethod"/>
然后在您的代码中:
public void nameOfMethod (View v){
//code when click the view
}
(这适用于所有视图,线性布局,图像视图,浓淡按钮...。全部)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.