将findViewById转换为Kotlin合成后,Android Lint显示UnusedIds

时间:2020-08-27 17:04:08

标签: android kotlin lint kotlin-extension

在我得到以下错误后,我将findViewById转换为kotlin合成。但是一切都一样。我之前有确切的问题。在这里,我通过在onCreateView()之后访问id(即onViewCreated())来解决它。在这里我不知道如何解决该问题?谢谢。

 The resource R.id.item_help_description appears to be unused [UnusedIds]

这是我的代码

internal class HelpAdapter(titleDescriptionMap: Map<String, String>) :
RecyclerView.Adapter<HelpAdapter.Item>() {
private var titles: Array<String> = titleDescriptionMap.keys.toTypedArray()
private var descriptions: Array<String> = titleDescriptionMap.values.toTypedArray()

override fun onCreateViewHolder(
   parent: ViewGroup,
   viewType: Int
): Item = Item(
LayoutInflater.from(parent.context)
  .inflate(R.layout.item_help, parent, false)
)

override fun onBindViewHolder(
holder: Item,
position: Int
) {
holder.itemView.item_help_description.text = descriptions[position]
holder.itemView.item_help_title.text = titles[position]
}

override fun getItemCount(): Int = titles.size

 internal inner class Item(itemView: View) :
RecyclerView.ViewHolder(itemView) {
init {
  itemView.item_help_title.setOnClickListener { toggleDescriptionVisibility() }
  itemView.item_help_toggle_expand.setOnClickListener { toggleDescriptionVisibility() }
}

@SuppressWarnings("MagicNumber")
fun toggleDescriptionVisibility() {
  if (itemView.item_help_description.visibility == View.GONE) {
    ObjectAnimator.ofFloat(itemView.item_help_toggle_expand, "rotation", 0f, 180f).start()
    itemView.item_help_description.expand()
  } else {
    ObjectAnimator.ofFloat(itemView.item_help_toggle_expand, "rotation", 180f, 360f).start()
    itemView.item_help_description.collapse()
  }
}
}
}

0 个答案:

没有答案