NavType
abstract class NavType<T : Any!>
kotlin.Any | |
↳ | androidx.navigation.NavType |
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.
Summary
Nested classes | |
---|---|
EnumType is used for |
|
ParcelableArrayType is used for |
|
ParcelableType is used for passing Parcelables in |
|
SerializableArrayType is used for |
|
open |
SerializableType is used for Serializable |
Public methods | |
---|---|
open static NavType<*> |
fromArgType(@Nullable : String?, @Nullable : String?) Parse an argType string into a NavType. |
abstract T? |
Get a value of this type from the |
abstract String |
getName() Returns the name of this type. |
open Boolean |
Check if an argument with this type can hold a null value. |
abstract T |
parseValue(@NonNull : String) Parse a value of this type from a String. |
abstract Unit |
Put a value of this type in he |
open String |
toString() |
Properties | |
---|---|
static NavType<BooleanArray!> |
NavType for storing boolean arrays, corresponding with the "boolean[]" type in a Navigation XML file. |
static NavType<Boolean!> |
NavType for storing boolean values, corresponding with the "boolean" type in a Navigation XML file. |
static NavType<FloatArray!> |
NavType for storing float arrays, corresponding with the "float[]" type in a Navigation XML file. |
static NavType<Float!> |
NavType for storing float values, corresponding with the "float" type in a Navigation XML file. |
static NavType<IntArray!> |
NavType for storing integer arrays, corresponding with the "integer[]" type in a Navigation XML file. |
static NavType<Int!> |
NavType for storing integer values, corresponding with the "integer" type in a Navigation XML file. |
static NavType<LongArray!> |
NavType for storing long arrays, corresponding with the "long[]" type in a Navigation XML file. |
static NavType<Long!> |
NavType for storing long values, corresponding with the "long" type in a Navigation XML file. |
static NavType<Int!> |
NavType for storing integer values representing resource ids, corresponding with the "reference" type in a Navigation XML file. |
static NavType<Array<String!>!> |
NavType for storing String arrays, corresponding with the "string[]" type in a Navigation XML file. |
static NavType<String!> |
NavType for storing String values, corresponding with the "string" type in a Navigation XML file. |
Public methods
fromArgType
@NonNull open static fun fromArgType(
@Nullable : String?,
@Nullable : 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. |
Return | |
---|---|
NavType<*> |
a NavType representing the type indicated by the argType string. Defaults to StringType for null. |
get
@Nullable abstract fun get(
@NonNull : Bundle,
@NonNull : String
): T?
Get a value of this type from the bundle
Parameters | |
---|---|
bundle |
Bundle: bundle to get value from |
key |
String: bundle key |
Return | |
---|---|
T? |
value of this type |
getName
@NonNull abstract fun getName(): String
Returns the name of this type.
This is the same value that is used in Navigation XML argType
attribute.
Return | |
---|---|
String |
name of this type |
isNullableAllowed
open fun isNullableAllowed(): Boolean
Check if an argument with this type can hold a null value.
Return | |
---|---|
Boolean |
Returns true if this type allows null values, false otherwise. |
parseValue
@NonNull abstract fun parseValue(@NonNull : String): T
Parse a value of this type from a String.
Parameters | |
---|---|
value |
String: string representation of a value of this type |
Return | |
---|---|
T |
parsed value of the type represented by this NavType |
Exceptions | |
---|---|
IllegalArgumentException |
if value cannot be parsed into this type |
put
abstract fun put(
@NonNull : Bundle,
@NonNull : String,
@Nullable : T?
): Unit
Put a value of this type in he bundle
Parameters | |
---|---|
bundle |
Bundle: bundle to put value in |
key |
String: bundle key |
value |
T?: value of this type |
toString
@NonNull open fun toString(): String
Properties
BoolArrayType
@NonNull static 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.
BoolType
@NonNull static 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
@NonNull static 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.
FloatType
@NonNull static 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
@NonNull static 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.
IntType
@NonNull static val IntType: NavType<Int!>
NavType for storing integer values, corresponding with the "integer" type in a Navigation XML file.
Null values are not supported.