как можно обновить Recyclerview при публикации комментария
Я уже закончил подключать БД, данные могут записываться в БД, но он не может показать мне новый комментарий при написании нового комментария.
Я не знаю, где возникла проблема, кто-то может мне помочь?
это мой код в HomeFragment
recyclerView = (RecyclerView) view.findViewById(R.id.recy_feed);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
listNewFeedModel = new ArrayList<>();
requestQueue = Volley.newRequestQueue(getActivity());
getData();
recyclerView.setOnScrollChangeListener(this);
adapter = new NewFeedAdapter(listNewFeedModel, getActivity());
recyclerView.setAdapter(adapter);
HomeFragment записать информацию в базу данных
private JsonArrayRequest getDataFromServer(int requestCount) {
final ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setMessage("Load...");
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(FeedConfig.DATA_URL + requestCount,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
parseData(response);
progressDialog.dismiss();
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
progressDialog.dismiss();
Toast.makeText(getContext(), "No More Items Available", Toast.LENGTH_SHORT).show();
}
});
progressDialog.dismiss();
return jsonArrayRequest;
}
private void getData() {
requestQueue.add(getDataFromServer(requestCount));
requestCount++;
}
private void parseData(JSONArray array) {
for (int i = 0; i < array.length(); i++) {
NewFeedModel newFeedModel = new NewFeedModel();
JSONObject json = null;
try {
json = array.getJSONObject(i);
Log.d("TAG_FeedGroupID", json.getString(FeedConfig.TAG_FeedGroupID));
newFeedModel.setFeedPostImageURL(json.getString(FeedConfig.TAG_FeedPostPhoto));
newFeedModel.setFeedPostName(json.getString(FeedConfig.TAG_FeedPostName));
newFeedModel.setFeedGroupName(json.getString(FeedConfig.TAG_FeedGroupName));
newFeedModel.setFeedInfo(json.getString(FeedConfig.TAG_FeedInfo));
newFeedModel.setFeedimageURL(json.getString(FeedConfig.TAG_FeedMediaPhoto_URL));
newFeedModel.setFeedTags(json.getString(FeedConfig.TAG_FeedTags));
newFeedModel.setFeedGroupID(json.getString(FeedConfig.TAG_FeedGroupID));
newFeedModel.setFeedID(json.getString(FeedConfig.TAG_FeedID));
newFeedModel.setTotalComment(json.getString(FeedConfig.TAG_TotalComment));
} catch (JSONException e) {
e.printStackTrace();
}
listNewFeedModel.add(newFeedModel);
}
adapter.notifyDataSetChanged();
}
это мой код адаптера
public class NewFeedAdapter extends RecyclerView.Adapter<NewFeedAdapter.ViewHolder> {
private ImageLoader imageLoader;
private Context context;
RequestManager glide;
private final int MENU_ITEM_VIEW_TYPE = 0;
private final int UNIFIED_NATIVE_AD_VIEW_TYPE = 1;
List<NewFeedModel> newFeedModels;
private String[] placeNames;
ImageView pphoto;
public NewFeedAdapter(List<NewFeedModel> newFeedModels, Context context){
super();
this.newFeedModels = newFeedModels;
this.context = context;
this.glide = Glide.with(context);
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.ifunpot_feed, parent, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
final NewFeedModel newFeedModel = newFeedModels.get(position);
imageLoader = CustomVolleyRequest.getInstance(context).getImageLoader();
holder.tv_uploader_name.setText(newFeedModel.getFeedPostName());
holder.tv_uploader_group.setText(newFeedModel.getFeedGroupName());
holder.post_info.setText(newFeedModel.getFeedInfo());
holder.tags.setText(newFeedModel.getFeedTags());
holder.gid.setText(newFeedModel.getFeedGroupID());
holder.feedid.setText(newFeedModel.getFeedID());
glide.load(newFeedModels.get(position).getFeedimageURL()).into(holder.uploader_pro_pic);
glide.load(newFeedModels.get(position).getFeedPostImageURL()).into(holder.post_pic);
}
@Override
public int getItemCount() {
return newFeedModels.size();
}
class ViewHolder extends RecyclerView.ViewHolder{
public ImageView uploader_pro_pic, post_pic;
public TextView tv_uploader_name, tv_uploader_group, post_info,tags, comments, gid,feedid, share, totalcomment;
LinearLayout parentLayout, infophoto;
final ImageView ppic;
public ViewHolder(View itemView) {
super(itemView);
uploader_pro_pic = (ImageView) itemView.findViewById(R.id.uploader_pro_pic);
post_info = (TextView) itemView.findViewById(R.id.post_info);
tv_uploader_name = (TextView) itemView.findViewById(R.id.tv_uploader_name);
tv_uploader_group = (TextView) itemView.findViewById(R.id.tv_uploader_group);
post_pic = (ImageView) itemView.findViewById(R.id.post_pic);
ppic = (ImageView) itemView.findViewById(R.id.post_pic);
parentLayout = itemView.findViewById(R.id.post_layout);
infophoto = itemView.findViewById(R.id.infophoto);
tags = itemView.findViewById(R.id.posttag);
comments = itemView.findViewById(R.id.comments);
gid = itemView.findViewById(R.id.gid);
feedid = itemView.findViewById(R.id.feedid);
share = itemView.findViewById(R.id.share);
//totalcomment = itemView.findViewById(R.id.totalcomment);
}
}
}
кто знает, в чем проблема? потому что он не может показать новый комментарий, когда я публикую новый комментарий. Мне нужно уйти или перейти на другую деятельность, а затем обратно.