【发布时间】:2021-12-04 03:59:05
【问题描述】:
当我从聊天片段更改为通话片段然后回来时,回收站视图的项目增加了一倍有任何解决方案吗? 无论如何请提出建议,因为我无法调试它。当我从聊天选项卡更改为通话选项卡然后再次返回聊天选项卡时,项目正在增加
聊天片段
package com.codewithdevesh.cackle.menu;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.codewithdevesh.cackle.PagerAdapter;
import com.codewithdevesh.cackle.R;
import com.codewithdevesh.cackle.adapter.ChatListAdapter;
import com.codewithdevesh.cackle.model.ChatListModel;
import java.util.ArrayList;
import java.util.List;
public class ChatsFragment extends Fragment {
public ChatsFragment() {
}
private List<ChatListModel> list = new ArrayList<>();
private RecyclerView rv;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_chats, container, false);
rv = v.findViewById(R.id.recycler_view);
rv.setLayoutManager(new LinearLayoutManager(getContext()));
getChatList();
return v;
}
private void getChatList() {
list.add(new ChatListModel("11","Devesh","good bye","15/10/2020","https://i.pinimg.com/550x/7d/1a/3f/7d1a3f77eee9f34782c6f88e97a6c888.jpg"));
list.add(new ChatListModel("12","Devesh","good bye","15/10/2020","https://i.pinimg.com/550x/7d/1a/3f/7d1a3f77eee9f34782c6f88e97a6c888.jpg"));
list.add(new ChatListModel("13","Devesh","good bye","15/10/2020","https://i.pinimg.com/550x/7d/1a/3f/7d1a3f77eee9f34782c6f88e97a6c888.jpg"));
list.add(new ChatListModel("14","Devesh","good bye","15/10/2020","https://i.pinimg.com/550x/7d/1a/3f/7d1a3f77eee9f34782c6f88e97a6c888.jpg"));
list.add(new ChatListModel("15","Devesh","good bye","15/10/2020","https://i.pinimg.com/550x/7d/1a/3f/7d1a3f77eee9f34782c6f88e97a6c888.jpg"));
rv.setAdapter(new ChatListAdapter(list,getContext()));
}
}
ChatListAdapter
package com.codewithdevesh.cackle.adapter;
import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.codewithdevesh.cackle.R;
import com.codewithdevesh.cackle.model.ChatListModel;
import com.mikhaellopez.circularimageview.CircularImageView;
import java.util.List;
public class ChatListAdapter extends RecyclerView.Adapter<ChatListAdapter.Holder> {
private final List<ChatListModel> list;
private final Context context;
@NonNull
@Override
public ChatListAdapter.Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(context).inflate(R.layout.chat_list_layout,parent,false);
return new Holder(v);
}
public ChatListAdapter(List<ChatListModel> list, Context context) {
this.list = list;
this.context = context;
}
@Override
public void onBindViewHolder(@NonNull ChatListAdapter.Holder holder, int position) {
ChatListModel chatListModel = list.get(position);
holder.tvName.setText(chatListModel.getUsrName());
holder.tvDesc.setText(chatListModel.getDescription());
holder.tvDate.setText(chatListModel.getDate());
Glide.with(context).load(chatListModel.getUrlProfile()).into(holder.profile);
}
@Override
public int getItemCount() {
return list.size();
}
public static class Holder extends RecyclerView.ViewHolder {
private TextView tvName,tvDesc,tvDate;
private CircularImageView profile;
public Holder(@NonNull View itemView) {
super(itemView);
tvDate = itemView.findViewById(R.id.tv_date);
tvName = itemView.findViewById(R.id.tv_name);
tvDesc = itemView.findViewById(R.id.tv_desc);
profile = itemView.findViewById(R.id.image_profile);
}
}
// public void setReceiverProfileImage(Bitmap bitmap){
// profileImage= bitmap;
// }
}
【问题讨论】:
标签: java android android-fragments android-recyclerview whatsapp