私はそれLinearLayout
にいくつかを持ってViews
います。次に、この要素を として扱いたいView
ので、 から新しいclass
拡張を作成しましたLinearLayout
。instance
これclass
をレイアウトに動的に追加すると、何も表示されません。View
からどうにかして を取得する必要があると思いますが、class
方法がわかりません。この新しいクラスを何らかの方法で xml に関連付けることは可能ですか?
アップデート:
public class Task extends LinearLayout {
public Task(Context context) {
super(context);
LayoutInflater.from(context).inflate(R.layout.task_view, this, false);
}
public Task(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.task_view, this, false);
}
public Task(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
LayoutInflater.from(context).inflate(R.layout.task_view, this, false);
}
}
それで:
Task newTask = new Task(getActivity());
someLinearLayout.addView((View) newTask); // happens nothing