我在android中有会议室数据库。但是,当我从数据库中检索数据并显示在可展开的RecyclerView
中时,它仅显示子列表中的最后一条记录。父母ArrayList
下有一个孩子ArrayList
。
我正在以hashmap
的键和值格式添加ExpandableListView
中来自数据库的数据
HashMap<String, List<Movies>> expandableListDetail = new HashMap<String, List<Movies>>();
ArrayList<String> moviecategoriess = new ArrayList<>();
for (int i = 0; i < tasks.size(); i++) {
childDataItems = new ArrayList<>();
String movieCategory = tasks.get(i).getMovieCategory();
String moviename = tasks.get(i).getMovieName();
String description = tasks.get(i).getMovieDescription();
String bannerimage = tasks.get(i).getMovieImage();
// String maincat=expandableListDetail.get("").get(i).
childDataItems.add(new Movies(moviename, bannerimage, description));
expandableListDetail.put(movieCategory, childDataItems);
moviecategoriess.add(movieCategory);
}
Iterator it = expandableListDetail.entrySet().iterator();
final ArrayList<MovieCategory> movieCategories = new ArrayList();
moviesArrayList = new ArrayList();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry) it.next();
String name = pairs.getKey().toString();
moviesArrayList = (ArrayList<Movies>) pairs.getValue();
movieCategories.add(new MovieCategory(name, moviesArrayList));
}
moviesAdapter = new MoviesAdapter(MovieActivity.this, movieCategories);
Functions.setDatatoRecyclerView(rv_movies_list, moviesAdapter, MovieActivity.this);
moviesAdapter.notifyDataSetChanged();
}
我想像这样在ArrayList
中显示数据
父项:惊悚片
列表中的ChildItems:
1)Force2
2)Sarkar2
父项:操作
列表中的ChildItems:
1)边框
2)战场
答案 0 :(得分:0)
在您的情况下,每次循环运行时都存在for循环问题,根据您的代码会创建一个新的数组列表,因此只需用以下代码替换代码即可:
HashMap<String, List<Movies>> expandableListDetail = new HashMap<String, List<Movies>>();
ArrayList<String> moviecategoriess = new ArrayList<>();
childDataItems = new ArrayList<>();
for (int i = 0; i < tasks.size(); i++) {
String movieCategory = tasks.get(i).getMovieCategory();
String moviename = tasks.get(i).getMovieName();
String description = tasks.get(i).getMovieDescription();
String bannerimage = tasks.get(i).getMovieImage();
// String maincat=expandableListDetail.get("").get(i).
childDataItems.add(new Movies(moviename, bannerimage, description));
expandableListDetail.put(movieCategory, childDataItems);
moviecategoriess.add(movieCategory);
}