У меня проблема при добавлении пользовательского представления динамически.
Ниже приведены мои текущие коды.
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="SkillItemView">
<attr name="skill" format="string" />
<attr name="proficiency" format="integer" />
</declare-styleable>
</resources>
skill_item.view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/progress_item_incomplete"
android:paddingTop="@dimen/list_row_margin_default"
android:paddingBottom="@dimen/list_row_margin_default"
android:paddingLeft="@dimen/text_padding"
android:paddingRight="@dimen/text_padding"
android:layout_margin="@dimen/list_row_margin_default">
<TextView
android:id="@+id/text_skill"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorBlack_2"
android:textStyle="italic"
android:text="Art Direction" />
</LinearLayout>
SkillItemView.kt
class SkillItemView (context: Context, attrs: AttributeSet): LinearLayout(context, attrs) {
init {
inflate(context, R.layout.skill_item_view, this)
val textSkill: TextView = findViewById(R.id.text_skill)
val attributes = context.obtainStyledAttributes(attrs, R.styleable.SkillItemView)
textSkill.text = attributes.getString(R.styleable.SkillItemView_skill)
attributes.recycle()
}
}
И я собираюсь динамически добавить это представление в адаптер
for (skill in profileList[position].getSkills()) {
var skillView = SkillItemView(context, ???)
parentView.addView(skillView)
}
Конструктор SkillItemView имеет 2 параметра. Context и AttributeSet. (См. ??? в кодах выше)
Что я должен написать для AttributeSet?