こんにちは、次のような単純なカスタム ビューを作成しましたGroup
。
public class Group extends LinearLayout {
private TextView headerTextView;
public Group(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray typedArray = context.obtainStyledAttributes(attrs,
R.styleable.Group, 0, 0);
String string = typedArray.getString(R.styleable.Group_headerText);
typedArray.recycle();
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.widget_group, this, true);
headerTextView = (TextView) v.findViewById(R.id.header_text);
headerTextView.setText(string);
}
}
アクティビティで動的に作成したい。カスタム属性属性を設定したいと思います。膨らませることでいくつかの解決策を見つけましたが、それを使用したくありません。オブジェクトを作成する適切な方法ではありません。この領域の例が必要です
Group g = new Group(v.getContext(),arrt);
arrt オブジェクトを設定してカスタム属性を設定する方法がわかりませんでした