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
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
@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
<?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
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
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
Integer intObj = null; | |
int primitiveInt; | |
primitiveInt = intObj; // NullPointerException during unboxing |
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 nullableStr: String? = null | |
var nonNullStr: String = "a string" | |
nullableStr = nonNullStr // valid | |
nonNullStr = nullableStr // error, should be checked for nullability first | |
If (nullableStr != null) { | |
nonNullStr = nullableStr // valid | |
} |
NewerOlder