2011-08-29 42 views
1

我是Android robotium的新手。我有自定義小部件(MyButton,MyTextView,MyCheckBox等),它從本地Android小部件繼承。如何在Robotium腳本中爲我的自定義控件添加單擊事件?我試過使用Solo.clickOnButton(「測試按鈕」),其中「測試按鈕」是MyButton的一個實例,但我沒有得到按鈕的單擊事件。任何建議都會非常有幫助。Robotium:如何使用clickOnButton(<name>)作爲自定義按鈕

感謝, -Ron ..

回答

0

我suposse創建myButton的使用擴展按鈕等等等等

好於ASIGN點擊動作,你應該使用的正常形態。對於expample

的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); 

然後ASIGN的onClick動作就像你與其他正常的按鈕來完成:

myButton.setOnclickListener(new onclickListener .... 

將onClickAction作爲所有視圖的其他方法是使用int 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 
    } 

(這適用於所有觀點,LinearLayout中,imageviews,bustom按鈕....所有)

+0

對不起我的問題不明確。我正在爲android使用robotium編寫一個測試腳本,它將自動點擊Button。如果我使用Solo.clickOnButton(),通常會執行點擊操作。但因爲我使用的是自定義按鈕,所以我無法點擊使用函數clickOnButton()。 – Ron

+0

對不起,我從來沒有使用Robotium:S無論如何嘗試創建你的按鈕的instacen按鈕myButton =(按鈕)findViewById(R.id.custom_button);並在robutium clickOnbutton方法中使用它。 – Aracem