2
ビュー所有者のビューを作成するために、recyckoViewアダプタでankoを使用しています。私はこれを正常に行っているが、それはビューidでkotlin合成を使用して参照する方法がわからない値/ ids.xmlでカスタムIDの参照を取得する方法
値/ ids.xml(私はfindViewByIdせずにそれを取得したい)
<resources>
<item name="txv1" type="id"/>
<item name="txv2" type="id"/>
マイアンコgetViewメソッドコード:
private fun getView(context: Context): View{
return with(context){
linearLayout {
lparams(width = matchParent, height = wrapContent)
padding = dip(10)
orientation = android.widget.LinearLayout.HORIZONTAL
//Task Number
textView {
id = R.id.txv1
text = "TextView 22"
textSize = 16f
typeface = Typeface.MONOSPACE
padding =dip(5)
}.lparams(){
weight = 1f
}
//Task Name
textView {
id = R.id.txv2
text= "TextView 33"
textSize = 16f
typeface = android.graphics.Typeface.DEFAULT_BOLD
padding =dip(5)
}
}
}
}
私はids.xmlからカスタムIDを割り当てるだが、どのよう
findViewByIdせずにそれを得るためにありがとう
私はAnkoと同じ問題に遭遇しました。回避策として現在、静的定数を静的定数として使用しています。例: オブジェクトID { @IdRes val toolbar = View.generateViewId();/* ... */ } '' – kirillkh