我在更改设备配置(更改语言、方向等)后进行了一些测试,我注意到在此之后,方法“notifyDataSetChanged()”不起作用。
动作示例:
每次我执行删除、保存等操作时,我都会调用 updateList()。当我更改方向或语言或设备的任何配置,然后单击对话框上的“是”,数据被删除,但列表不会更新。我需要退出活动,然后回去查看更改。
图书适配器:
public void updateList(ArrayList<Book> books) {
bookList = books;
notifyDataSetChanged();
}
配置更改后我该怎么做才能使其正常工作?
编辑:
BookAdapter 构造函数:
public BookAdapter(Context c, ArrayList<Book> books) {
context = c;
bookList = books
bookDAO = BookDAO.getInstance(context);
}
书段:
public class BookFragment extends Fragment {
private BookDAO bookDAO;
private BookAdapter bookAdapter;
private ListView listBook;
private View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
bookDAO = bookDAO.getInstance(getActivity());
view = inflater.inflate(R.layout.book_tab, container, false);
ArrayList<Book> listBook = null;
try {
llistBook = bookDAO.getAll();
} catch (Exception e) {
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
return view;
}
bookAdapter = new BookAdapter(getActivity(), listBook);
listBook = (ListView)view.findViewById(R.id.listBook);
listBook.setAdapter(bookAdapter);
return view;
}
}