由于后台要求买家留言需要传json格式,所以下面对多个门店下的卖家留言进行的组装: 新建一个HashMap把每个门店的id作为key区分每个门店的买家留言 HashMap<Integer,String> remarkMap=new HashMap<>(); class MyTextWatcher implements TextWatcher { private ChildViewHolder mHolder; public MyTextWatcher(ChildViewHolder mHolder) { this.mHolder = mHolder; } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { int groupPosition = (int) mHolder.confirmOrderLeaveAMessageEditText.getTag();//取tag值 int merchantId = groupList.get(groupPosition).getMerchantId(); mRemark=""; remarkMap.put(merchantId,s.toString()); Set<Map.Entry<Integer, String>> entries = remarkMap.entrySet(); for (Map.Entry<Integer, String> entry : entries) { int key = entry.getKey(); String value = entry.getValue(); String id="\""+key+"\""; String str="\""+value+"\""; mRemark+=id+":"+str+","; } mRemark="{"+mRemark.substring(0,mRemark.length()-1)+"}"; if (mOnRemarkTextChangeListener!=null) { mOnRemarkTextChangeListener.OnRemarkTextChange(mRemark); } } }