public class DataBindingUtil extends Object
DataBinding that obtains DataBinding objects.
You can define attributes of the class to be bound in a layout file.
After compilation, the corresponding DataBinding child class will be automatically generated.
You can call the createBinding(int,ohos.app.Context,java.lang.String) method to obtain
the generated DataBinding child class object for further initialization and binding.
DataBindingSystemCapability.Aafwk#ABILITYJET| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static <T extends DataBinding> |
createBinding(int layoutId,
Context context) |
Obtains the declared
DataBinding object based on the given layout file ID and Context object. |
static <T extends DataBinding> |
createBinding(int layoutId,
Context context,
String packageName) |
Obtains the declared
DataBinding object based on the given layout file ID, Context object,
and HAP package name. |
public static <T extends DataBinding> T createBinding(int layoutId, Context context) throws IOException
DataBinding object based on the given layout file ID and Context object.
You must specify a valid layout file ID and Context object as the input parameters.
Otherwise, this method will throw an exception.
layoutId - Indicates the ID of the resource layout file.context - Indicates the application context.DataBinding child class object if one has been declared;
returns null otherwise.IOException - Throws this exception if the specified resource layout file fails to be accessed.IllegalArgumentException - Throws this exception if a parameter value is invalid.public static <T extends DataBinding> T createBinding(int layoutId, Context context, String packageName) throws IOException
DataBinding object based on the given layout file ID, Context object,
and HAP package name.
You must specify a valid layout file ID, Context object, and HAP package name as the input parameters.
Otherwise, this method will throw an exception.
layoutId - Indicates the ID of the resource layout file.context - Indicates the application context.packageName - Indicates the package name of the specified HAP (module).DataBinding child class object if one has been declared;
returns null otherwise.IOException - Throws this exception if the specified resource layout file fails to be accessed.IllegalArgumentException - Throws this exception if a parameter value is invalid.