pocorall / scaloid

Scaloid makes your Android code easy to understand and maintain.
Other
2.09k stars 163 forks source link

How to initialize LocalServiceConnection from a fragment #149

Open ndarilek opened 8 years ago

ndarilek commented 8 years ago

I have code like:

class MapFragment extends Fragment with Contexts[Fragment] with SharedPreferences.OnSharedPreferenceChangeListener {

  implicit var ctx:Context = _

  override def onActivate(a:Activity) {
    ctx = a
    val locationService = new LocalServiceConnection[LocationService]
    locationService.onConnected {
...

But I get:

/home/nolan/Projects/Hermes/src/main/scala/android/ui.scala:371: could not find implicit value for parameter reg: org.scaloid.common.Registerable
Error occurred in an application involving default arguments.
    val locationService = new LocalServiceConnection[LocationService]
                          ^

How do I make this custom Fragment a Registerable?

Thanks.

pocorall commented 8 years ago

Missing part is an implicit value of Registerable:

implicit val reg = new Registerable {
  def onRegister(body: => Any) = ???
  def onRegister(body: => Any) = ???
}

You can easily write one for yourself when you refer the implementation for SActivity.

ndarilek commented 8 years ago

Got it. Stupid question, but what should the ??? do? What steps related to registering the connection from the fragment does the Registerable need to accomplish?