我想在擴展視圖的類中調用我的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