Created
July 13, 2019 14:51
-
-
Save harmittaa/ed414c814f4133a009b7661c2a41f819 to your computer and use it in GitHub Desktop.
Koin 2.0 example fragment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.os.Bundle | |
import android.util.Log | |
import android.view.LayoutInflater | |
import android.view.View | |
import android.view.ViewGroup | |
import androidx.fragment.app.Fragment | |
import androidx.lifecycle.Observer | |
import com.github.harmittaa.koinexample.R | |
import org.koin.androidx.viewmodel.ext.android.viewModel | |
import org.koin.dsl.module | |
val fragmentModule = module { | |
factory { ExampleFragment() } | |
} | |
class ExampleFragment : Fragment() { | |
val exampleViewModel: ExampleViewModel by viewModel() | |
private val observer = Observer<String> { | |
Log.d("ExampleFragment", "Data: $it") | |
} | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | |
super.onCreateView(inflater, container, savedInstanceState) | |
exampleViewModel.fragmentContent.observe(this, observer) | |
return inflater.inflate(R.layout.fragment_view, container, false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment