ビューを拡張するクラスでXMLレイアウトファイルを呼び出すとします。私はそれが活動を拡張しないので、oncreate機能を実行できません。私のイベントは1つのクラスファイルにあり、私は別のクラスファイルでそのクラスを呼び出しています。 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
あなたのクラスはXMLでアンドロイドのように使用できますか? – dreamtale