我想創建一個CustomButton
它有一個預定義的onClick
。 事實上,我的目標會做的比Android按鈕onclick覆蓋
CustomButton mButton = getViewById(..);
mButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
show_something()
}
同樣的工作,有沒有一種方法嵌入到Listener
從按鍵繼承的CustomButton對象? 我想是建立在我的佈局XML文件中的CustomButton
,並沒有提到在我的活動這個按鈕,這將使:
的main.xml:
<LinearLayout xmlns:"...">
<com.mypackage.view.CustomButton
(attributes)/>
</LinearLayout>
CustomButton.java:
class CustomButton extends Button implements... {
@Override
OnClick (or something like that, that's the core of my question, what to put here)
}
myActivity.java
public class myActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
非常感謝。