java中viewList方法,尽管在绑定类中可用,但找不到符号方法setUser_list_user_view(User_List_UserViewModel)...

While implementing MVVM architecture with Data Binding and Live Data run into problem with getting error "cannot find symbol method setUser_list_user_view(User_List_UserViewModel)" I have done many time rebuild, cleanup and other stuff but this error not going..I am doing this first time so not sure have implemented the right method. Below is my code. Thnx in advance for the help

User_List_UserViewModel.java

public class User_List_UserViewModel extends AndroidViewModel {

private User_List_UserRepository mRepository;

private LiveData> mAllUser;

public User_List_UserViewModel(Application application) {

super(application);

mRepository = new User_List_UserRepository(application);

mAllUser = mRepository.getmUserlist();

}

LiveData> getAllWords() {

return mAllUser;

}

public void insert(User user) {

mRepository.insert(user);

}

}

User_List_UserAdapter.java

public class User_List_UserAdapter extends RecyclerView.Adapter {

private LayoutInflater mInflater;

private List user_list_userViewModels;

class User_List_ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {

private PeopleListItemBinding mBinding;

private TextView mFirst_NameTextView;

public User_List_ViewHolder(PeopleListItemBinding itemBinding) {

super(itemBinding.getRoot());

mBinding = itemBinding;

}

public void bind(User_List_UserViewModel user_list_userViewModel) {

this.mBinding.setUser_list_user_view(user_list_userViewModel);

mBinding.executePendingBindings();

}

public PeopleListItemBinding getPeopleListItemBInding() {

return mBinding;

}

@Override

public void onClick(View v) {

}

}

public User_List_UserAdapter(List newsList) {

this.user_list_userViewModels = newsList;

}

@NonNull

@Override

public User_List_ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

if (mInflater == null) {

mInflater = LayoutInflater.from(parent.getContext());

}

PeopleListItemBinding peopleListItemBinding = DataBindingUtil.inflate(mInflater, R.layout.people_list_item, parent, false);

return new User_List_ViewHolder(peopleListItemBinding);

}

@Override

public void onBindViewHolder(@NonNull User_List_ViewHolder holder, int position) {

User_List_UserViewModel userViewModel = user_list_userViewModels.get(position);

holder.bind(userViewModel);

}

@Override

public int getItemCount() {

if (user_list_userViewModels != null)

return user_list_userViewModels.size();

else return 0;

}

}

People_List_Fragment.java

public class People_List_Fragment extends Fragment {

List user_list = new ArrayList<>();

@Nullable

@Override

public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup

container, Bundle savedInstanceState) {

final RecyclerView rv = (RecyclerView) inflater.inflate(

R.layout.people_list, container, false);

rv.setLayoutManager(new LinearLayoutManager(rv.getContext()));

rv.setAdapter(new User_List_UserAdapter(user_list));

return rv;

}

}

解决方案

welcome to data binding.

You have not shown your layout so I can not see what is variable name, you have taken in your layout. But here is an example, which will explain you trick.

1> Create

>

name="item"

type="com.sample.User_List_UserViewModel"/>

android:layout_width="match_parent"

android:layout_height="wrap_content">

2> Now you can use setItem(User_List_UserViewModel)

public void bind(User_List_UserViewModel model) {

this.mBinding.setItem(model);

}

Dont use long or confusing variable name

name="User_List_UserViewModel"

type="com.sample.User_List_UserViewModel"/>

Use short names, easy to use

name="item"

type="com.sample.User_List_UserViewModel"/>

Suggestions

You could make model name just UserModel, why so long name?

You can make UserAdapter, again why a confusing name.

Update

Please see this answer if you classes or variables are not generated. https://stackoverflow.com/a/51579759/6891563

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值