Java 如何更新复杂的recyclerview项参数?
以下是我的帖子:Java 如何更新复杂的recyclerview项参数?,java,android-recyclerview,Java,Android Recyclerview,以下是我的帖子: public class PostItems { private String id_wall_post, id_user, text_wall_post, ..........; public PostItems(String id_wall_post, String id_user, String text_wall_post, ..............) { this.id_wall_post = id_wall_post;
public class PostItems {
private String id_wall_post, id_user, text_wall_post, ..........;
public PostItems(String id_wall_post, String id_user, String text_wall_post, ..............) {
this.id_wall_post = id_wall_post;
this.id_user = id_user;
this.text_wall_post = text_wall_post;
}
String get_id_wall_post() {
return id_wall_post;
}
String get_id_user() {
return id_user;
}
String get_text_wall_post() {
return text_wall_post;
}
...
...
.........
...
...
}
这里是我的适配器:
public class PostAdapter extends RecyclerView.Adapter<PostAdapter.PostViewHolder> {
private List<PostItems> postList;
private Context context;
PostAdapter(List<PostItems> postList, Context context) {
this.postList = postList;
this.context = context;
}
@NonNull
@Override
public PostViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_view_wall_post, parent, false);
return new PostViewHolder(v);
}
@Override
public void onBindViewHolder(@NonNull PostViewHolder holder, int position) {
PostItems post_items = postList.get(position);
...
...
.........
...
...
}
@Override
public int getItemCount() {
return postList.size();
}
static class PostViewHolder extends RecyclerView.ViewHolder {
PostViewHolder(@NonNull View itemView) {
super(itemView);
}
}
}
我还有一个Editext,用户可以在其中更新text\u wall\u post的值;现在我想更新recyclerView的项目参数text\u wall\u post
如何更新recyclerView项目特定参数
编辑:
我发现:
在我的recyclerView中,我有20多个参数。
这是可行的,但我想要一种更干净的方法,只更新所需的参数,而不更新所有参数
感谢您的帮助。您可以更改项目,而无需创建新项目。 首先创建setter(就像您创建的getter)来更改对象中的特定参数(
positems
在本例中)您还可以通过按
Alt+Inser
>Setter
然后从postList
获取具有特定位置的项目,并更新所需的参数postList.get(position).setTextWallPost("new value here");
最后打电话给postAdapter.notifyItemChanged (position)
我不确定您的问题,但似乎回收视图实际上是空的,因为您没有为任何项目设置值。@首先,回收视图不是空的,它是在改装查询成功后填充的。请在特定位置在
postList
中更新text\u wall\u pos
,然后调用postAdapter.notifyItemChanged(position)
尝试更新postList中的text\u wall\u pos,如何更新?我不知道怎么做,所以我来这里寻求帮助。
public class PostItems {
private String id_wall_post, id_user, text_wall_post, ..........;
public PostItems(String id_wall_post, String id_user, String text_wall_post, ..............) {
this.id_wall_post = id_wall_post;
this.id_user = id_user;
this.text_wall_post = text_wall_post;
}
String get_id_wall_post() {
return id_wall_post;
}
String get_id_user() {
return id_user;
}
String get_text_wall_post() {
return text_wall_post;
}
public void setIdWallPost(String idWallpost){
this.id_wall_post = idWallpost;
}
public void setIdUser(String idUser){
this.id_user = idWallUser;
}
public void setTextWallPost(String textWallPost){
this.text_wall_post = textWallPost;
}
...
...
.........
...
...
}
postList.get(position).setTextWallPost("new value here");
postAdapter.notifyItemChanged (position)