我想在扩展视图的类中调用我的XML布局文件。我不能执行oncreate函数,因为它没有扩展Activity。我的事件在一个类文件中,我在另一个类文件中调用该类;但我想在XML布局文件上执行这些事件。Android - 在扩展类中调用xml布局文件查看
这里是我的代码:
Demo.java
public class Demo extends Activity
{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new another(this));
}
another.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
..
..
怎么办呢?
你能发布abc.xml吗? – Blackbelt 2012-03-22 11:11:49
你想让你的类可以像android视图一样在XML中使用吗? – dreamtale 2012-03-22 12:12:14