Skip to content

Commit

Permalink
7.0.4.2
Browse files Browse the repository at this point in the history
- 尝试使用新方法获取ViewBinding对象;
  • Loading branch information
kongzue committed Nov 26, 2024
1 parent 69189de commit 6a2013e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ private View userDataBindingCreateLayout() {
Type type = parameterizedType.getActualTypeArguments()[0];
try {
Class<VB> clazz = (Class<VB>) type;
binding = (VB) clazz.getMethod("inflate", getLayoutInflater().getClass()).invoke(null, getLayoutInflater());
LayoutInflater layoutInflater = LayoutInflater.from(this);
binding = (VB) clazz.getMethod("inflate", LayoutInflater.class).invoke(null, layoutInflater);
return binding.getRoot();
} catch (Exception e) {
throw new RuntimeException("ViewBinding creation failed", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ private View userDataBindingCreateLayout() {
Type superclass = getClass().getGenericSuperclass();
if (superclass instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) superclass;
Type type = parameterizedType.getActualTypeArguments()[1];
Type type = parameterizedType.getActualTypeArguments()[0];
try {
Class<VB> clazz = (Class<VB>) type;
binding = (VB) clazz.getMethod("inflate", getLayoutInflater().getClass()).invoke(null, getLayoutInflater());
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
binding = (VB) clazz.getMethod("inflate", LayoutInflater.class).invoke(null, layoutInflater);
return binding.getRoot();
} catch (Exception e) {
throw new RuntimeException("ViewBinding creation failed", e);
Expand Down

0 comments on commit 6a2013e

Please sign in to comment.