与工作@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, HashMapalternatives, String topic) { PieChartHelper.initializePieChart(pieChart,alternatives,topic); }
我的XML布局
奇怪的是,我为其他观点做了类似的解决方案.但这是唯一一个完整的自定义视图.那么PieChart类不能以这种方式支持数据绑定吗?
使用的库可以在https://github.com/PhilJay/MPAndroidChart找到
你的BindingAdapter是一个private
方法.成功public
:
@BindingAdapter({"bind:alternatives","bind:topic"}) public static void setPieChartData(PieChart pieChart, HashMapalternatives, String topic) { PieChartHelper.initializePieChart(pieChart,alternatives,topic); }