Posts

Showing posts from September, 2019

Scrollable readonly EditView in Kotlin

In the view xml file: <EditTextandroid:id="@+id/etResult" android:layout_width="match_parent" android:layout_height="343dp" android:background="@color/backgroundColor" android:backgroundTint="#00000000" android:ems="10"android:enabled="true"android:fontFamily="sans-serif-condensed"android:gravity="start|top"android:hint="@string/blankfoldermessage"android:importantForAutofill="no"android:inputType="none"android:paddingTop="2dp"android:singleLine="false"tools:targetApi="o" />in the kotlin file (init function): etResult.keyListener = nullthis will allow the edit text to be multiline, not editable but scrollable.

Simple use of Timer in Kotlin

the code below will set the button to clickable after 30 sec:btnOk.isClickable=falseTimer().schedule(timerTask {     btnOk.isClickable=true }, 1000*30)the above code runs in a separate thread, so the UI is responsive while running this code.

Working with UI controls from Non main thread in Kotlin

import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread

fun anyFunction(){ doAsync {// Normal code inside Async threadI=I+1If(I=100){uiThread { tvResult.setText =”I is now 100!!”}}//More codeIf(x==0){uiThread { tvResult.setText =”there’s some problem!”}} }}
Note: - you can include multiple uiThread inside same doAsync           - you can include multiple doAsync inside any function