listview绑定适配器后,数据更新不是需要调用notifyDataSetChanged刷新数据吗,为什么我现在不用掉也能刷新,平台是4.2和4.4,低的平台没测。代码如下
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
listview = (ListView)findViewById(R.id.listview);
listview.setAdapter(adapter);
btn = (Button)findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
adapter.add("item");
}
});
/**
* Adds the specified object at the end of the array.
*
* @param object The object to add at the end of the array.
*/
public void add(T object) {
synchronized (mLock) {
if (mOriginalValues != null) {
mOriginalValues.add(object);
} else {
mObjects.add(object);
}
}
if (mNotifyOnChange) notifyDataSetChanged();
}
这个是源代码 最后已经帮你调用notify了。 建议有问题先自己分析。