【发布时间】:2018-06-20 10:06:57
【问题描述】:
在组视图的 BaseExpandableListAdapter 上有一个按钮,用于在其子项中添加 cmets。将项目添加到列表并在该适配器类中调用 notifyDataSetChanged() 时,它不会立即更改,而是在折叠和展开列表后更改。
private List<String> ParentItem;
private LinkedHashMap<String, List<JsonCase>> ChildItem;
public View getChildView(final int listPosition, final int expandedListPosition,boolean isLastChild, View convertView, final ViewGroup parent) {
final JsonCase expandedListText = (JsonCase) getChild(listPosition, expandedListPosition);
if (convertView == null) {
LayoutInflater layoutInflater = (LayoutInflater) this.context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = layoutInflater.inflate(R.layout.hearing_detail,parent, false);
}
final EditText comment = (EditText) convertView.findViewById(R.id.comment);
TextView commentorName = (TextView) convertView.findViewById(R.id.commentorName);
TextView commentDate = (TextView) convertView.findViewById(R.id.commentDate);
comment.setText("" + expandedListText.details);
if(expandedListText.commentorName!=null &&expandedListText.commentorName.equals("")){
commentorName.setEnabled(false);
}else{
commentorName.setText(expandedListText.commentorName);
}
commentDate.setText(expandedListText.date);
return convertView;
}
public void addCaseHearingsToAdapter(int listPosition){
String hearingId = this.ChildItem.get(this.ParentItem.get(listPosition)).get(0).hearingId;
String userId = PreferenceData.getLoggedInUserId(context);
JsonCase comment = new JsonCase();
comment.commentId = "";
comment.hearingId = hearingId;
comment.commentedBy = userId;
comment.details = "";
comment.commentorName = "";
comment.date = new SimpleDateFormat("dd MMMM yyyy hh:mm:ss").format(Calendar.getInstance().getTime());
this.ChildItem.get(this.ParentItem.get(listPosition)).add(comment);
this.notifyDataSetChanged();
}
【问题讨论】:
标签: java android expandablelistview expandablelistadapter notifydatasetchanged