当前位置:  开发笔记 > Android > 正文

绑定适配器无效元素问题

如何解决《绑定适配器无效元素问题》经验,为你挑选了1个好方法。

与工作@BindingAdapter一直正常,直到如今.我得到一个不寻常的问题,我没有看到如何解决它的明确路径.

堆栈跟踪

@BindingAdapter on invalid element: setPieChartData(com.github.mikephil.charting.charts.PieChart,java.util.HashMap,java.lang.String)
    at com.sun.tools.javac.main.Main.compile(Main.java:553)
    at com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:129)
    at com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:138)
    at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:46)
    at org.gradle.api.internal.tasks.compile.JdkJavaCompiler.execute(JdkJavaCompiler.java:33)
    at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.delegateAndHandleErrors(NormalizingJavaCompiler.java:104)
    at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:53)
    at org.gradle.api.internal.tasks.compile.NormalizingJavaCompiler.execute(NormalizingJavaCompiler.java:38)
    at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:35)
    at org.gradle.api.internal.tasks.compile.CleaningJavaCompilerSupport.execute(CleaningJavaCompilerSupport.java:25)
    at org.gradle.api.tasks.compile.JavaCompile.performCompilation(JavaCompile.java:206)
    at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:187)
    at org.gradle.api.tasks.compile.JavaCompile.compile(JavaCompile.java:130)
    at com.android.build.gradle.tasks.factory.AndroidJavaCompile.compile(AndroidJavaCompile.java:49)
    at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$IncrementalTaskAction.doExecute(DefaultTaskClassInfoStore.java:163)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
    at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
    at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)

我的功能

@BindingAdapter({"bind:alternatives","bind:topic"})
private static void setPieChartData(PieChart pieChart, HashMap alternatives, String topic) {
    PieChartHelper.initializePieChart(pieChart,alternatives,topic);
}

我的XML布局

     

奇怪的是,我为其他观点做了类似的解决方案.但这是唯一一个完整的自定义视图.那么PieChart类不能以这种方式支持数据绑定吗?

使用的库可以在https://github.com/PhilJay/MPAndroidChart找到



1> George Mount..:

你的BindingAdapter是一个private方法.成功public:

@BindingAdapter({"bind:alternatives","bind:topic"})
public static void setPieChartData(PieChart pieChart, HashMap alternatives, String topic) {
    PieChartHelper.initializePieChart(pieChart,alternatives,topic);
}

推荐阅读
ar_wen2402851455
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有