我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按鈕....所有)
對不起我的問題不明確。我正在爲android使用robotium編寫一個測試腳本,它將自動點擊Button。如果我使用Solo.clickOnButton(),通常會執行點擊操作。但因爲我使用的是自定義按鈕,所以我無法點擊使用函數clickOnButton()。 –
Ron
對不起,我從來沒有使用Robotium:S無論如何嘗試創建你的按鈕的instacen按鈕myButton =(按鈕)findViewById(R.id.custom_button);並在robutium clickOnbutton方法中使用它。 – Aracem