0
我遇到與下列對象進行數據綁定的問題。我有一個對象類調用ScanInfo看起來像這樣。Android數據綁定:錯誤:未指定資源類型
public class ScanInfo extends BaseObservable implements Parcelable {
private BarcodeItem barcodeItem;
private ParcelInfo parcelInfo;
private int childCount = 0;
private boolean showQuantity;
private boolean showDeviation;
private boolean hasParcel;
private boolean hasBarcode;
public ScanInfo(BarcodeItem barcodeItem) {
this.barcodeItem = barcodeItem;
}
public ScanInfo(ParcelInfo parcelInfo) {
this.parcelInfo = parcelInfo;
}
public ScanInfo(BarcodeItem barcodeItem, ParcelInfo parcelInfo) {
this.barcodeItem = barcodeItem;
this.parcelInfo = parcelInfo;
}
@Bindable
public BarcodeItem getBarcodeItem() {
return barcodeItem;
}
public void setBarcodeItem(BarcodeItem barcodeItem) {
this.barcodeItem = barcodeItem;
notifyPropertyChanged(BR.hasBarcode);
}
@Bindable
public ParcelInfo getParcelInfo() {
return parcelInfo;
}
public void setParcelInfo(ParcelInfo parcelInfo) {
this.parcelInfo = parcelInfo;
notifyPropertyChanged(BR.hasParcel);
}
@Bindable
public boolean isHasParcel() {
return hasParcel;
}
@Bindable
public boolean isHasBarcode() {
return hasBarcode;
}
public void setChildCount(int childCount) {
this.childCount = childCount;
}
public void setShowQuantity(boolean showQuantity) {
this.showQuantity = showQuantity;
}
public void setShowDeviation(boolean showDeviation) {
this.showDeviation = showDeviation;
}
@Bindable
public String getBarcodeContent() {
return barcodeItem.getContent();
}
}
我將它綁定到來自適配器和適配器的列表項getView方法我已經這樣做了。
convertView = _inflater.inflate(R.layout.barcode_list_item, parent, false);
BarcodeListItemBinding binding = BarcodeListItemBinding.bind(convertView);
ScanInfo scanInfo = getItem(position);
BarcodeItem barcodeItem = scanInfo.getBarcodeItem();
if (barcodeItem != null) {
scanInfo.setChildCount(getChildCount(barcodeItem));
scanInfo.setShowQuantity(barcodeItem.getQuantity() > 1 || (barcodeItem.getQuantity() == 1 && _showParcelQuantityOne));
scanInfo.setShowDeviation(_deviations != null && _deviations.size() > 0 && hasDeviation(barcodeItem));
}
binding.setScanInfo(scanInfo);
binding.executePendingBindings();
和列表項的資源文件看起來像這樣
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="android.view.View" />
<import type="xx.xxx.xxx.BarcodeItem" />
<import type="xx.xxx.xxx.ParcelInfo" />
<variable
name="scanInfo"
type="xx.xxx.xxx.ScanInfo" />
</data>
...
<TextView
android:id="@+id/textBarcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="middle"
android:gravity="top"
android:singleLine="true"
android:textAppearance="?android:textAppearanceMedium"
android:visibility="visible"
android:text="@{scanInfo.barcodeItem.content}"
tools:text="123123123123ABABABABABABABA" />
...
</layout>
但是,當我編譯它總是給出了以下錯誤
F:\ ExProjects ... \事件\ 4.171.1.0 \ res \ layout \ barcode_list_item.xml:57:31-62:AAPT:無資源 指定的e類型(在'text'中,值爲'@ {scanInfo.barcodeItem.content}')。
我想知道我在這裏做錯了什麼。請幫我解決這個問題。
你使用:'dataBinding.enabled = TRUE;在你的build.gradle文件? –
[Gradle:沒有指定資源類型('text',值爲'@ {user.name}')的可能重複。數據綁定不工作](http://stackoverflow.com/questions/37723767/gradle-no-resource-type-specified-at-text-with-value-user-name-databi) – tynn
@GeorgeMount是的,我已經用它在我正在處理的模塊在將其添加到所有其他模塊後,它可以工作。 – Sanath