【发布时间】:2018-03-02 12:37:32
【问题描述】:
过去三天我一直试图解决这个问题,但无济于事。我正在从连接在一起的两个数据库表中检索数据(表名是“类”和“节”)。下图描述了该问题。
每个学校班级(一年级,二年级等)应显示每个被点击班级的部分(一年级班级1A级,二年级班级2A级等)。但从图像中,所有类都显示相同(类部分),而与单击的类无关。
问题
如何使每个部分显示在各自的类中? 示例代码将不胜感激。如果有办法获取 recyclerViewItem 的 Id 并将其与 classes 表中类名的 Id 匹配,我将感谢代码示例。
这是我在适配器类的onBindViewHolder() 中所做的。我认为错误来自这里
@Override
public void onBindViewHolder(final ClassSectionOnSetupRecyclerAdapter.ViewHolderCSOS holder, final int position) {
holder.textView_classname_sections.setText(listClassesCSOS.get(position).getClasses_name());
holder.layoutt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
// still thinking on how to apply this(this gets the ItemId of the recyclerview Items)
long itemId = getRVItemId(position);
Log.i("itemId", String.valueOf(itemId));
if (holder.expandableCardView.isShown()) {
holder.expandableCardView.setVisibility(View.GONE);
} else {
holder.expandableCardView.setVisibility(View.VISIBLE);
if(itemId == listClassesCSOS.get(position).getId()) {
StringBuilder sb = new StringBuilder();
listClassesCSOS = demeaSQL.getAllSectionsByClassesID();
// not used yet
sectionsList = demeaSQL.getAllSections();
// getAllSections()
for (ClassesBean c : listClassesCSOS ){
sb.append(c.sectionBeanGetName() + "\n" + "\n");
// sets the textView with data from database after a class name has been clicked
holder.addedSectionTV.setText(sb.toString());
}
}
}
}
});
holder.add_class_section.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showAddSectionsDialog();
}
});
}
【问题讨论】:
-
你可以使用嵌套的recyclerview,也可以使用headers (section recyclerview)
-
感谢您的回答@Santanu_Sur 这是如何工作的。很抱歉这样的问题,但我是这个 android 的新手
-
@pskink 是的,我做到了
-
您可以通过编程方式实现这一点,但由于您是新手,您可以试试这个库..
标签: android sqlite android-recyclerview