-
-
Save le0nidas/9e0817baaed43f83bf23a9261b302eeb to your computer and use it in GitHub Desktop.
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
class MainActivity : AppCompatActivity() { | |
private var timer = Timer() | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val bindings = ActivityMainBinding.inflate(layoutInflater) | |
setContentView(bindings.root) | |
with(bindings) { | |
userInput.doAfterTextChanged { text -> | |
timer.cancel() // cancel any previous delay | |
timer = Timer() // schedule a new one | |
timer.schedule(500L) { | |
// we are in a background thread here | |
userInput.handler.post { userResult.text = text } | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment