我使用ListView来显示我的项目。当项目改变我更新适配器列表,并调用notifyDataSetChanged()
:Android ListView无法正常刷新
MyAdapter adapter = (MyAdapter) myListView.getAdapter();
if(adapter == null) {
adapter = new MyAdapter(this, itemList);
myListView.setAdapter(adapter);
}
adapter.notifyDataSetChanged();
这似乎在某种程度上工作,因为我的ListView显示更多的项目,但在列表中的新项目没有得到正确显示。
这些项目不显示任何信息。看起来适配器没有刷新这些新项目。
适配器看起来像这样(简化):
public View getView(int position, View convertView, ViewGroup parent) {
Point point = getItem(position);
if (convertView == null)
convertView = LayoutInflater.from(getContext()).inflate(R.layout.item_point, parent, false);
TextView firstLine = (TextView) convertView.findViewById(R.id.firstLine);
firstLine.setText(point.getNumber());
}
请检查控制台。数据是否正确检索或不。如果它是正确的,并检查项目的大小。 – sivaprakash
数据没有问题。 –
也许数据不会传递给数组列表。你尝试过adapter.notifyItemInserted(arraylistsize) – sivaprakash