Created
June 14, 2020 13:48
-
-
Save GregKluska/2cf9da39f4f3aee5684363d58cec303b to your computer and use it in GitHub Desktop.
Check if the content implements an interface
This file contains hidden or 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.content.Context | |
| import androidx.fragment.app.Fragment | |
| import com.codingwithmitch.mviexample.ui.DataStateListener | |
| import java.lang.ClassCastException | |
| class ExampleFragment : Fragment() { | |
| lateinit var dataStateHandler: DataStateListener | |
| override fun onAttach(context: Context) { | |
| super.onAttach(context) | |
| try { | |
| dataStateHandler = context as DataStateListener | |
| }catch(e: ClassCastException) { | |
| println("DEBUG: $context must implement DataStateListener") | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment