我想在扩展视图的类中调用我的 XML 布局文件。我无法在其中执行 oncreate 功能,因为它不扩展 Activity。我的事件在一个类文件中,我在另一个类文件中调用该类;但我想在 XML 布局文件上执行这些事件。
这是我的代码:
演示.java
public class Demo extends Activity
{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new another(this));
}
另一个.java
public class another extends View
{
public anotherView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}
public anotherView(Context context) {
super(context);
init();
}
public anotherView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
private void init() {
setWillNotDraw(false);
...
..
..
}
和 XML 文件
abc.xml
..
..
怎么做?