开发者

Robotium: how to use clickOnButton(<name>) for custom buttons

I am new to Android robotium. I am having custom widgets(MyButton, MyTextView, MyCheckBox etc..,) which got inherited from native android widgets. How can i add a click event for my custom controls in a robotium script?

I tried using Solo.clickOnButton("Test Button") where the "Test Button" is an instance of MyButton, but i am not getting click ev开发者_StackOverflow社区ent for the Button. Any suggestions would be really helpful.

Thanks, -Ron..


I suposse you create the MyButton using extend Button etc etc

Well to asign click action you should use the normal form. For expample

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:

 myButton.setOnclickListener(new onclickListener ....

Other method to asing onClickAction to all views is use int the 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 )

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜