Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Bindings to custom container based on ViewContainer #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pablow91
Copy link

@pablow91 pablow91 commented Jan 5, 2015

I have migrated one of my small project from Java to Kotlin. I replaced Butterknife with Kotterknife for view injections, but I was unable to proper inject views in two cases (there is probably much more):

  • To create dialog I used DialogFragment class and create Dialog object on onCreateDialog method. It cause exception, because DialogFragment.getView return null instead of dialog view.
  • Creating optimal ListAdapter might be difficult with Kotterknife. To create optimal ListAdapter I would like to use this code (or something similar - I just started learning Kotlin):
val view: View = preView ?: LayoutInflater.from(context).inflate(R.layout.list_item, parent,false)
val c: Container = preView?.getTag() as Container? ?: Container(view)
if (preView == null) {
    view.setTag(c);
}
c.item.setText(getItem(position))
return view

That is why I created ViewContainer class with can be used to solved both problems. In Butterknife I tend to use ButterKnife.inject(container, view) in such situations.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant