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
@Composable | |
fun SearchBox( | |
onBackClick: () -> Unit, | |
) { | |
var searchText by remember { mutableStateOf("") } | |
Row( | |
horizontalArrangement = Arrangement.spaced(16.dp), | |
) { | |
Icon( |
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
@Preview | |
@Composable | |
fun CustomViewPreview( | |
@PreviewParameter(ViewStateProvider::class) params: PreviewParams, | |
) { | |
AndroidView( | |
modifier = Modifier | |
.fillMaxWidth() | |
.background(Color.White) | |
.padding(8.dp), |
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
private val previewItems = listOf( | |
mapOf( | |
"Dimension" to "34x12x8", | |
), | |
mapOf( | |
"Display" to "6.4 inches", | |
"Resolution" to "1080x2340" | |
), | |
mapOf( | |
"OS" to "Android 10", |
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
<?xml version="1.0" encoding="utf-8"?> | |
<merge xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:background="@drawable/background_info_view" | |
android:padding="16dp" | |
tools:parentTag="androidx.constraintlayout.widget.ConstraintLayout" | |
> |
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 OrderView @JvmOverloads constructor( | |
context: Context, | |
attrs: AttributeSet? = null | |
) : ConstraintLayout(context, attrs) { | |
private val binding = ViewOrderBinding.inflate(LayoutInflater.from(context), this) | |
init { | |
setPadding(context.dpToPx(16)) | |
background = context.drawable(R.drawable.background_info_view) |
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
val nonNullInt = 1 | |
val nullInt: Int? = null | |
if (nullInt == nonNullInt) { | |
println("Both are equal") | |
} else { | |
println("Not equal") // Result is 'Not equal' | |
} |
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
Integer nullInt = null; | |
if (someInt.equals(23)) { // NullPointerException because of attempt to call | |
// a method on a null | |
// Rest of code | |
} |
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
var nonNullInt = 1 | |
val nullInt: Int? = null | |
// 1. Error | |
nonNullInt = nullInt // Error: type mismatch | |
// 2. Valid | |
if (nullInt != null) { | |
/* Here is used a smart cast (one of Kotlin compiler's feature), | |
which casts Int? to Int automatically */ | |
nonNullInt = nullInt | |
} |
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
val someStr1: String? = null // valid statement, notice a question mark after 'String' | |
val someStr2: String? // warning: no default value assigned. Should be initialized | |
// with some (nullable or non-nullable) value before its first use |
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 Test(val someInt: Int) | |
val test1: Test // warning: no default value, should be initialized | |
// with non-null value before first use | |
val test2: Test = null // error: non-nullable type can't hold null value | |
val test3: Test? = null // valid |
NewerOlder