NavType
public abstract class NavType<T extends Object>
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 extends Object> |
the type of the data that is supported by this NavType |
Summary
Nested types |
|---|
public static class NavType.Companion |
public final class NavType.EnumType<D extends Enum<@NonNull ?>> extends NavType.SerializableTypeEnumType is used for |
public final class NavType.ParcelableArrayType<D extends Parcelable> extends NavTypeParcelableArrayType is used for |
public final class NavType.ParcelableType<D extends Object> extends NavTypeParcelableType is used for passing Parcelables in |
public final class NavType.SerializableArrayType<D extends Serializable> extends NavTypeSerializableArrayType is used for |
public class NavType.SerializableType<D extends Serializable> extends NavTypeSerializableType is used for Serializable |
Public fields |
|
|---|---|
static final @NonNull NavType<@NonNull Integer> |
NavType for storing integer values representing resource ids, corresponding with the "reference" type in a Navigation XML file. |
Public methods |
|
|---|---|
static @NonNull NavType<@NonNull ?> |
fromArgType(String type, String packageName)Parse an argType string into a NavType. |
abstract T |
Get a value of this type from the |
abstract T |
get(@NonNull SavedState bundle, @NonNull String key)Get a value of this type from the |
@NonNull String |
getName()The name of this type. |
boolean |
Check if an argument with this type can hold a null value. |
abstract @NonNull T |
parseValue(@NonNull String value)Parse a value of this type from a String. |
@NonNull T |
parseValue(@NonNull String value, @NonNull T previousValue)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. |
abstract void |
Put a value of this type in the |
abstract void |
Put a value of this type in the |
@NonNull String |
serializeAsValue(@NonNull T value)Serialize a value of this NavType into a String. |
@NonNull String |
toString() |
@NonNull String |
toString() |
boolean |
valueEquals(@NonNull T value, @NonNull T other)Compares two values of type |
Public fields
ReferenceType
public static final @NonNull NavType<@NonNull Integer> ReferenceType
NavType for storing integer values representing resource ids, corresponding with the "reference" type in a Navigation XML file.
Null values are not supported.
Public constructors
Public methods
fromArgType
public static @NonNull NavType<@NonNull ?> fromArgType(String type, String packageName)
Parse an argType string into a NavType.
| Parameters | |
|---|---|
String type |
argType string, usually parsed from the Navigation XML file |
String packageName |
package name of the R file, used for parsing relative class names starting with a dot. |
| Returns | |
|---|---|
@NonNull NavType<@NonNull ?> |
a NavType representing the type indicated by the argType string. Defaults to StringType for null. |
| Throws | |
|---|---|
IllegalArgumentException |
if there is no valid argType |
RuntimeException |
if the type class name cannot be found |
get
public abstract T get(@NonNull Bundle bundle, @NonNull String key)
Get a value of this type from the savedState
| Returns | |
|---|---|
T |
value of this type |
get
public abstract T get(@NonNull SavedState bundle, @NonNull String key)
Get a value of this type from the savedState
| Parameters | |
|---|---|
@NonNull SavedState bundle |
savedState to get value from |
@NonNull String key |
savedState key |
| Returns | |
|---|---|
T |
value of this type |
getName
public @NonNull String getName()
The name of this type.
This is the same value that is used in Navigation XML argType attribute.
isNullableAllowed
public boolean isNullableAllowed()
Check if an argument with this type can hold a null value.
| Returns | |
|---|---|
boolean |
Returns true if this type allows null values, false otherwise. |
parseValue
public abstract @NonNull T parseValue(@NonNull String value)
Parse a value of this type from a String.
| Returns | |
|---|---|
@NonNull T |
parsed value of the type represented by this NavType |
| Throws | |
|---|---|
IllegalArgumentException |
if value cannot be parsed into this type |
parseValue
public @NonNull T parseValue(@NonNull String value, @NonNull T previousValue)
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 | |
|---|---|
@NonNull String value |
string representation of a value of this type |
@NonNull T previousValue |
previously parsed value of this type |
| Returns | |
|---|---|
@NonNull T |
combined parsed value of the type represented by this NavType |
| Throws | |
|---|---|
IllegalArgumentException |
if value cannot be parsed into this type |
put
public abstract void put(@NonNull Bundle bundle, @NonNull String key, @NonNull T value)
Put a value of this type in the savedState
put
public abstract void put(@NonNull SavedState bundle, @NonNull String key, @NonNull T value)
Put a value of this type in the savedState
| Parameters | |
|---|---|
@NonNull SavedState bundle |
savedState to put value in |
@NonNull String key |
savedState key |
@NonNull T value |
value of this type |
serializeAsValue
public @NonNull String serializeAsValue(@NonNull T value)
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 | |
|---|---|
@NonNull T value |
a value representing this NavType to be serialized into a String |