NavType
CollectionNavType |
A |
NavType.ParcelableArrayType |
ParcelableArrayType is used for |
NavType.ParcelableType |
ParcelableType is used for passing Parcelables in |
NavType.SerializableArrayType |
SerializableArrayType is used for |
NavType.SerializableType |
SerializableType is used for Serializable |
NavType.EnumType |
EnumType is used for |
NavType denotes the type that can be used in a NavArgument.
There are built-in NavTypes for primitive types, such as int, long, boolean, float, and strings, parcelable, and serializable classes (including Enums), as well as arrays of each supported type.
You should only use one of the static NavType instances and subclasses defined in this class.
| Parameters | |
|---|---|
<T : Any?> |
the type of the data that is supported by this NavType |
Summary
Nested types |
|---|
class NavType.EnumType<D : Enum<*>> : NavType.SerializableTypeEnumType is used for |
class NavType.ParcelableArrayType<D : Parcelable> : NavTypeParcelableArrayType is used for |
class NavType.ParcelableType<D : Any?> : NavTypeParcelableType is used for passing Parcelables in |
class NavType.SerializableArrayType<D : Serializable> : NavTypeSerializableArrayType is used for |
open class NavType.SerializableType<D : Serializable> : NavTypeSerializableType is used for Serializable |
Public companion functions |
||
|---|---|---|
open NavType<*> |
fromArgType(type: String?, packageName: String?)Parse an argType string into a NavType. |
Cmn
android
|
Public companion properties |
||
|---|---|---|
NavType<BooleanArray?> |
NavType for storing boolean arrays, corresponding with the "boolean[]" type in a Navigation XML file. |
Cmn
android
|
NavType<List<Boolean>?> |
NavType for storing list of Booleans. |
Cmn
android
|
NavType<Boolean> |
NavType for storing boolean values, corresponding with the "boolean" type in a Navigation XML file. |
Cmn
android
|
NavType<FloatArray?> |
NavType for storing float arrays, corresponding with the "float[]" type in a Navigation XML file. |
Cmn
android
|
NavType<List<Float>?> |
NavType for storing list of Floats. |
Cmn
android
|
NavType<Float> |
NavType for storing float values, corresponding with the "float" type in a Navigation XML file. |
Cmn
android
|
NavType<IntArray?> |
NavType for storing integer arrays, corresponding with the "integer[]" type in a Navigation XML file. |
Cmn
android
|
NavType<List<Int>?> |
NavType for storing list of Ints. |
Cmn
android
|
NavType<Int> |
NavType for storing integer values, corresponding with the "integer" type in a Navigation XML file. |
Cmn
android
|
NavType<LongArray?> |
NavType for storing long arrays, corresponding with the "long[]" type in a Navigation XML file. |
Cmn
android
|
NavType<List<Long>?> |
NavType for storing list of Longs. |
Cmn
android
|
NavType<Long> |
NavType for storing long values, corresponding with the "long" type in a Navigation XML file. |
Cmn
android
|
NavType<Int> |
NavType for storing integer values representing resource ids, corresponding with the "reference" type in a Navigation XML file. |
android
|
NavType<Array<String>?> |
NavType for storing String arrays, corresponding with the "string[]" type in a Navigation XML file. |
Cmn
android
|
NavType<List<String>?> |
NavType for storing list of Strings. |
Cmn
android
|
NavType<String?> |
NavType for storing String values, corresponding with the "string" type in a Navigation XML file. |
Cmn
android
|
Public functions |
||
|---|---|---|
abstract operator T? |
android
|
|
abstract operator T? |
get(bundle: SavedState, key: String)Get a value of this type from the |
Cmn
|
abstract T |
parseValue(value: String)Parse a value of this type from a String. |
Cmn
android
|
open T |
parseValue(value: String, previousValue: T)Parse a value of this type from a String and then combine that parsed value with the given previousValue of the same type to provide a new value that contains both the new and previous value. |
Cmn
android
|
abstract Unit |
android
|
|
abstract Unit |
put(bundle: SavedState, key: String, value: T)Put a value of this type in the |
Cmn
|
open String |
serializeAsValue(value: T)Serialize a value of this NavType into a String. |
Cmn
android
|
open String |
toString() |
android
|
open Boolean |
valueEquals(value: T, other: T)Compares two values of type |
Cmn
android
|
Public properties |
||
|---|---|---|
open Boolean |
Check if an argument with this type can hold a null value. |
Cmn
android
|
open String |
The name of this type. |
Cmn
android
|
Public companion functions
fromArgType
open fun fromArgType(type: String?, packageName: String?): NavType<*>
Parse an argType string into a NavType.
| Parameters | |
|---|---|
type: String? |
argType string, usually parsed from the Navigation XML file |
packageName: String? |
package name of the R file, used for parsing relative class names starting with a dot. |
| Returns | |
|---|---|
NavType<*> |
a NavType representing the type indicated by the argType string. Defaults to StringType for null. |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if there is no valid argType |
kotlin.RuntimeException |
if the type class name cannot be found |
Public companion properties
BoolArrayType
val BoolArrayType: NavType<BooleanArray?>
NavType for storing boolean arrays, corresponding with the "boolean[]" type in a Navigation XML file.
Null values are supported. Default values in Navigation XML files are not supported.
BoolListType
val BoolListType: NavType<List<Boolean>?>
NavType for storing list of Booleans.
Null values are supported. List NavTypes in Navigation XML files are not supported.
BoolType
val BoolType: NavType<Boolean>
NavType for storing boolean values, corresponding with the "boolean" type in a Navigation XML file.
Null values are not supported.
FloatArrayType
val FloatArrayType: NavType<FloatArray?>
NavType for storing float arrays, corresponding with the "float[]" type in a Navigation XML file.
Null values are supported. Default values in Navigation XML files are not supported.
FloatListType
val FloatListType: NavType<List<Float>?>
NavType for storing list of Floats.
Null values are supported. List NavTypes in Navigation XML files are not supported.
FloatType
val FloatType: NavType<Float>
NavType for storing float values, corresponding with the "float" type in a Navigation XML file.
Null values are not supported.
IntArrayType
val IntArrayType: NavType<IntArray?>
NavType for storing integer arrays, corresponding with the "integer[]" type in a Navigation XML file.
Null values are supported. Default values in Navigation XML files are not supported.
IntListType
val IntListType: NavType<List<Int>?>
NavType for storing list of Ints.
Null values are supported. List NavTypes in Navigation XML files are not supported.
IntType
val IntType: NavType<Int>
NavType for storing integer values, corresponding with the "integer" type in a Navigation XML file.
Null values are not supported.
LongArrayType
val LongArrayType: NavType<LongArray?>
NavType for storing long arrays, corresponding with the "long[]" type in a Navigation XML file.
Null values are supported. Default values in Navigation XML files are not supported.
LongListType
val LongListType: NavType<List<Long>?>
NavType for storing list of Longs.
Null values are supported. List NavTypes in Navigation XML files are not supported.
LongType
val LongType: NavType<Long>
NavType for storing long values, corresponding with the "long" type in a Navigation XML file.
Null values are not supported. Default values for this type in Navigation XML files must always end with an 'L' suffix, e.g. app:defaultValue="123L".
ReferenceType
val ReferenceType: NavType<Int>
NavType for storing integer values representing resource ids, corresponding with the "reference" type in a Navigation XML file.
Null values are not supported.
StringArrayType
val StringArrayType: NavType<Array<String>?>
NavType for storing String arrays, corresponding with the "string[]" type in a Navigation XML file.
Null values are supported. Default values in Navigation XML files are not supported.
StringListType
val StringListType: NavType<List<String>?>
NavType for storing list of Strings.
Null values are supported. List NavTypes in Navigation XML files are not supported.
StringType
val StringType: NavType<String?>
NavType for storing String values, corresponding with the "string" type in a Navigation XML file.
Null values are supported.
Public functions
get
abstract operator fun get(bundle: SavedState, key: String): T?
Get a value of this type from the savedState
| Parameters | |
|---|---|
bundle: SavedState |
savedState to get value from |
key: String |
savedState key |
| Returns | |
|---|---|
T? |
value of this type |
parseValue
abstract fun parseValue(value: String): T
Parse a value of this type from a String.
| Parameters | |
|---|---|
value: String |
string representation of a value of this type |
| Returns | |
|---|---|
T |
parsed value of the type represented by this NavType |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if value cannot be parsed into this type |
parseValue
open fun parseValue(value: String, previousValue: T): T
Parse a value of this type from a String and then combine that parsed value with the given previousValue of the same type to provide a new value that contains both the new and previous value.
By default, the given value will replace the previousValue.
| Parameters | |
|---|---|
value: String |
string representation of a value of this type |
previousValue: T |
previously parsed value of this type |
| Returns | |
|---|---|
T |
combined parsed value of the type represented by this NavType |
| Throws | |
|---|---|
kotlin.IllegalArgumentException |
if value cannot be parsed into this type |
put
abstract fun put(bundle: SavedState, key: String, value: T): Unit
Put a value of this type in the savedState
| Parameters | |
|---|---|
bundle: SavedState |
savedState to put value in |
key: String |
savedState key |
value: T |
value of this type |
serializeAsValue
open fun serializeAsValue(value: T): String
Serialize a value of this NavType into a String.
By default it returns value of kotlin.toString or null if value passed in is null.
This method can be override for custom serialization implementation on types such custom NavType classes.
Note: Final output should be encoded with NavUriUtils.encode
| Parameters | |
|---|---|
value: T |
a value representing this NavType to be serialized into a String |
valueEquals
open fun valueEquals(value: T, other: T): Boolean
Compares two values of type T and returns true if values are equal.
| Parameters | |
|---|---|
value: T |
the first value for comparison |
other: T |
the second value for comparison |
Public properties
isNullableAllowed
open val isNullableAllowed: Boolean
Check if an argument with this type can hold a null value.
| Returns | |
|---|---|
Boolean |
Returns true if this type allows null values, false otherwise. |