java - 通过调用 notifyDataSetChange 未在运行时更新可扩展列表视图适配器子
问题描述
组视图上的 BaseExpandableListAdapter 上有一个按钮,用于在其子项中添加评论。将项目添加到列表并在该适配器类中调用 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();
}
解决方案
你能尝试刷新适配器吗
getActivity().runOnUiThread(new Runnable() {
public void run() {
this.notifyDataSetChanged();
}
});
推荐阅读
- wordpress - 将特定员工添加到 wordpress 中的页面
- c# - 将文件添加到 Flurl 多部分 POST 请求时,IFormFileCollection 为空
- python-3.x - Pywin32服务启动失败,无法读取json文件
- javascript - 如何使用 Foundation 修复响应式网站中的手风琴错误
- python - Matplotlib 子图轴共享:适用于其他所有图?
- matlab - Collapsing and averaging redundant entries in MATLAB table
- windows - Windows 的 Docker Engine 版本 18.XX.X 是否存在,如果存在,我该如何下载?
- powershell - 如何在 PowerShell 中将嵌套哈希表转换为 PSObjects
- c# - 简单的异步任务无法在 Wpf 应用程序中继续,但在控制台应用程序中有效
- reactjs - 如何在自定义 3d 对象(.obj)上添加自定义 3d 对象材质(.mtl)?