Skip to content

Instantly share code, notes, and snippets.

Artem Hluhovskyi hluhovskyi

Block or report user

Report or block hluhovskyi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View medium_2.kt
private lateinit var errorMessage: TextView
override fun onCreate(savedInstanceState: Bundle?) {
errorMessage = findViewById(R.id.error_message) as TextView
}
View medium_1.java
private TextView errorMessage;
@Override
protected void onCreate(Bundle savedInstanceState) {
errorMessage = (TextView) findViewById(R.id.error_message);
}
View medium_3.kt
fun <T : View> Activity.getViewById(@IdRes id: Int): T {
return findViewById(id) as T
}
View medium_4.kt
private lateinit var errorMessage: TextView
override fun onCreate(savedInstanceState: Bundle?) {
errorMessage = getViewById(R.id.error_message)
}
View medium_5.kt
private val errorMessage: TextView by lazy { getViewById(R.id.error_message) }
View medium_6.kt
class ViewFinderDelegate<T : View> : ReadOnlyProperty<Activity, T> {
private object EMPTY
private val id: Int
private var view: Any? = Empty
constructor(@IdRes id: Int) {
this.id = id
}
View medium_7.kt
private val errorMessage: TextView by ViewFinderDelegate(R.id.error_message)
View medium_8.kt
fun <T : View> Activity.view(IdRes id: Int): ReadOnlyProperty<Activity, T>
= ViewFinderDelegate(id)
View medium_9.kt
private val errorMessage: TextView by view(R.id.errorMessage)
View medium_10.kt
interface ContextProvdier {
fun provideContext(): Context
}
class OwnActivity : AppCompatActivity(), ContextProvider {
fun provideContext() = this
}
class OwnFragment : Fragment(), ContextProvider {
fun provideContext() = context
You can’t perform that action at this time.