Hello. Tell me please what am I doing wrong? My adapter takes data from the server and puts it in the foliage. Then, when new data arrives, I try to update the adapter ... and as if everything is fine, but .. When new data arrives, for example 2 messages, they are added to the adapter. But along with the new data, all the other old data are also added .. Although I see from the logs that I don’t have the old data received from the server. It turns out that I do not perform data.clear() . I data.clear() ... data.clear() , my foliage becomes absolutely empty until the next request Handler.postDelayed(); . Again the request is complete with foliage and with new data ... 5 seconds passes and my sheet is again clean ... and so constantly. How to overcome this?

 public class ChatMsgAdapter extends ArrayAdapter<ResponseMsgArray> { private Context context; private ArrayList<ResponseMsgArray> data; protected String LV_KEY = Auth.key; protected int LV_USID = Integer.parseInt(Auth.id); protected int GET_ID = Integer.parseInt(FriendActivity.get_id); String LOG_TAG = "FriendLOG"; public ChatMsgAdapter(Context context, ArrayList<ResponseMsgArray> values) { super(context,R.layout.activity_friend_msg, values); this.data = values; this.context = context; } @Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = LayoutInflater.from(context); View v; int type = getItemViewType(position); if(type == LV_USID) { v = inflater.inflate(R.layout.activity_friend_msg_adapter, null); TextView user_id_msg = (TextView) v.findViewById(R.id.id_msg); TextView user_text = (TextView) v.findViewById(R.id.msg); TextView user_date = (TextView) v.findViewById(R.id.msg_time); user_text.setText(data.get(position).getMsg()); user_date.setText(data.get(position).getMsg_time()); user_id_msg.setText(data.get(position).getMsg_id()); } else if (type == GET_ID) { v = inflater.inflate(R.layout.talker, null); TextView talker_text = (TextView) v.findViewById(R.id.msg); TextView talker_date = (TextView) v.findViewById(R.id.msg_time); talker_text.setText(data.get(position).getMsg()); talker_date.setText(data.get(position).getMsg_time()); } else { //Если нет например сообщений v = inflater.inflate(R.layout.msg_null, null); } return v; } public void setData(ArrayList<ResponseMsgArray> newData) { addAll(newData); notifyDataSetChanged(); } @Override public int getItemViewType(int position) { int newPosition = Integer.parseInt(data.get(position).getMsg_id_us()); return newPosition; } } 
  • Show the ChatMsgAdapter adapter ChatMsgAdapter . - post_zeew
  • In the sense of? This is the standard method - sergei1094
  • Show the code for the entire adapter. - post_zeew
  • Updated his question - sergei1094
  • @post_zeew, will you tell me? - sergei1094

1 answer 1

Duplicate values ​​are shown due to the fact that there is no default setting. When creating an element, try setting its values ​​to empty first, and then processing it with the help of if...else