Please tell me what I'm doing wrong? I adapter receives data from the server and places them in the foliage. Then, when new data arrive, I try to update the adapter ... and as if all is well, but when it comes .. the new data, eg 2 messages, they are added to the adapter. But with the new data are added to all the other old dannye..Hotya logs on can see that the old data received I do not have a server. It turns out that it is not doing data.clear (). I carry ... data.clear (), my foliage becomes completely empty until the next request Handler.postDelayed () ;. Again request - full foliage and the new data ... 5 seconds passed and my clean sheet again ... and so constantly. How to overcome it?
My Adapter:
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;
}
}
Text translated with the help of an interpreter. Thank you for understanding. Here in this post https://ru.stackoverflow.com/questions/579311/%d0%9f%d0%b5%d1%80%d0%b5%d0%b4%d0%b0%d1%87%d0%b0-%d0%b4%d0%b0%d0%bd%d0%bd%d1%8b%d1%85-%d0%b2-%d0%b4%d1%80%d1%83%d0%b3%d0%be%d0%b9-%d0%ba%d0%bb%d0%b0%d1%81%d1%81/579403?noredirect=1#comment769066_579403 are all my current classes