私はそれ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