-
Couldn't load subscription status.
- Fork 160
Open
Description
I've run into issues attempting to do the following:
class MyFragment extends ListFragment with TraitContext[Context] {
override def basis = getActivity
lazy val adapter = new MyAdapter
override def onCreate(savedInstanceState: Bundle) = {
super.onCreate(savedInstanceState)
setListAdapter(adapter)
}
//Actual data is given to the adapter later, though the data itself is irrelevant
}
class MyAdapter(implicit context: Context) extends BaseAdapter {
def layoutInflater = LayoutInflater.from(context)
override def getView(index: Int, convertView: View, parent: ViewGroup) = {
if (convertView == null) {
layoutInflater.inflate(...) // Error occurs here
}
}
}The issue stems from the fact that getActivity returns null at the point where implicit val ctx = basis is evaluated. This could be fixed if ctx were changed to a def or a lazy val.
Metadata
Metadata
Assignees
Labels
No labels