我正在使用listview
进行社交应用程序以显示来自数据库的信息。当我看到 listview 工作正常但如果我从应用程序添加新数据然后再次转到listview
应用程序崩溃。我认为问题是因为我没有实施notifyDataSetChanged()
而我必须这样做,但我不知道如何做到这一点。
起初我有一个功能来接收数据库中的照片和信息,然后我有一个class ImageAdapter extends BaseAdapter
。我认为这个方法必须放在这个类中:
class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context context) {
mContext = context;
}
public int getCount() {
return MyArrList.size();
}
public Object getItem(int position) {
return MyArrList.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
有人知道如何在我的applciation中实现这个功能吗?
例外情况如下:
java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(2131165257, class android.widget.ListView) with Adapter(class com.xx.xx.app.Listview$ImageAdapter)]
由于