这种行为是不正常的。在没有看到您的代码的情况下,我可以建议以下内容:
1) 你没有打电话notifyDataSetChanged()
来自 UI 线程。正确的做法:
runOnUiThread(new Runnable() {
public void run() {
adapter.notifyDataSetChanged();
}
});
2) 您无意中或无意中拨打了adapter.notifyDataSetInvalidated();
3)在你的适配器中你覆盖adapter.notifyDataSetChanged();
方法并添加了转到顶部的说明
4) 如果您使用列表来填充适配器 - 您每次都提供新列表,因此适配器设置会刷新。您应该始终提供相同的列表。但是您可以根据需要更改它。如果您要重置列表,请使用list.clear
代替list = new ArrayList();
这是我的适配器的示例:
public class Adapter extends BaseAdapter {
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater = null;
public ImageLoader imageLoader;
public MediaItemAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data = d;
inflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader = new ImageLoader(activity.getApplicationContext());
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
if (convertView == null) {
vi = inflater.inflate(R.layout.item_composer, null);
}
TextView title = (TextView) vi.findViewById(R.id.item_title); // title
TextView price = (TextView) vi.findViewById(R.id.price);
return vi;
}
}
致电索取适配器:
List myList = new ArrayList<HashMap<String, String>>();
Adapter ma = new Adapter(this, myList);
在适配器初始化之前 myList 可以为空。
然后对我的列表进行一些操作:
myList.add(someElement);
ma.notifyDataSetChanged();
如果您需要删除所有项目:
myList.clear();
ma.notifyDataSetChanged();
这样的实现是无穷无尽的,我看到了超过 15000 个元素,没有任何问题。