也許有人在這裏可以向我解釋爲什麼這不起作用,我怎麼能解決它。從XML文件查看數據綁定錯誤與視圖屬性
<com.projet.Core.Views.ProfileInfoItemView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:setNumber='@{account.posts.intValue()}'
app:setTitle="Posts"/>
片段上面的代碼中不起作用。但是,它完美的作品,如果我硬編碼的值。
attrs.xml
<declare-styleable name="ProfileInfoTextView">
<attr name="setNumber" format="integer" />
<attr name="setTitle" format="string" />
</declare-styleable>
段從ProfileInfoTextView類
private void initialize(Context context, AttributeSet attributeSet) {
mRoot = inflate(context, R.layout.custom_profile_info_textview_container,this);
mNumberTextView = (TextView) mRoot.findViewById(R.id.custom_profile_info_number_text_view);
mTitleTextView = (TextView) mRoot.findViewById(R.id.custom_profile_info_title_text_view);
if(attributeSet != null) {
TypedArray a = context.getTheme().obtainStyledAttributes(
attributeSet,
R.styleable.ProfileInfoTextView,
0, 0);
try {
mTitleTextView.setText(a.getString(R.styleable.ProfileInfoTextView_setTitle));
String number = getNumber(a.getInt(R.styleable.ProfileInfoTextView_setNumber,1000));
mNumberTextView.setText(number);
} finally {
a.recycle();
}
}
}
片段從賬戶類
public class Account {
private Integer posts;
public Integer getPosts() {
return posts;
}
public void setPosts(Integer posts) {
this.posts = posts;
}
}
Account.class
是自動生成的GreenDao數據類。
我想傳入的值是整數或整數。兩者都不起作用。只有當我在xml文件中硬編碼它。 異常消息
Caused by: java.lang.RuntimeException: Found data binding errors.
****/ data binding error ****msg:Cannot find the setter for attribute 'app:setNumber' with parameter type java.lang.String on com.projet.Core.Views.ProfileInfoItemView. file:/Users/jemilriahi/ProjectNinjo/app/src/main/res/layout/fragment_my_account.xml loc:81:35 - 81:63 ****\ data binding error ****
at android.databinding.tool.processing.Scope.assertNoError(Scope.java:110)
at android.databinding.annotationprocessor.ProcessDataBinding.process(ProcessDataBinding.java:76)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:794)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:705)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.access$1800(JavacProcessingEnvironment.java:91)
at com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1035)
at com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1176)
at com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1170)
at com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:856)
at com.sun.tools.javac.main.Main.compile(Main.java:523)
誰知道爲什麼它不工作的原因嗎?所有幫助表示讚賞
你可以分享'account'和它的'posts'字段的類類型。 – yigit
加了:)但是那個班沒有太多 –