我做了很多研究,发现@ = {}用于双向绑定。但是,如果我使用sysbol,我会收到绑定包不可用的错误。
如果我使用@ {}数据绑定工作正常。但这只是一种方式。
以下是我用来绑定编辑文本视图的代码。
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable
name="ItemPricing"
type="com.san.viewmodels.Item.ItemPricing" />
</data>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1">
<EditText
android:id="@+id/item_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@={String.valueOf(ItemPricing.unitPrice1)}" />
</android.support.design.widget.TextInputLayout>
</layout>
这是适配器
public class ItemPricingRecylerAdapter extends RecyclerView.Adapter<ItemPricingRecylerAdapter.DataViewHolder> {
private LayoutInflater inflater;
List<ItemPricing> data = Collections.emptyList();
Context context;
public ItemPricingRecylerAdapter(List<ItemPricing> data, Context context) {
inflater = LayoutInflater.from(context);
this.data = data;
this.context = context;
}
@Override
public DataViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
ItemLayoutBinding binding = ItemLayoutBinding.inflate(inflater);
DataViewHolder dataViewHolder = new DataViewHolder(binding);
return dataViewHolder;
}
@Override
public void onBindViewHolder(DataViewHolder holder, int position) {
ItemPricing current = data.get(position);
holder.cBinding.setItemPricing(current);
}
@Override
public int getItemCount() {
return data.size();
}
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
class DataViewHolder extends RecyclerView.ViewHolder {
ItemLayoutBinding cBinding;
public DataViewHolder(ItemLayoutBinding binding) {
super(binding.getRoot());
this.cBinding = binding;
}
}
}
如果我使用@ = {}
,我收到ItemLayoutBinding包的错误这是POJO模型
public class ItemPricing {
private int unitPrice1;
public int getUnitPrice1() {
return this.unitPrice1;
}
public void setUnitPrice1(int unitPrice1) {
this.unitPrice1 = unitPrice1;
}}
我做错了什么?我很长时间没能解决这个问题。
请有人知道如何解决此问题
答案 0 :(得分:0)
@ = {user.email}
机器人:文本=&#39; @ = {ItemPricing.unitPrice1 +&#34;&#34;}&#39;
你可以尝试这种方式吗?