From your question, I made an example of a PLS check if this helps.
RecyclerView
public class RecyclerViewActivity extends AppCompatActivity implements CategoryClickListener {
private RecyclerView recyclerViewCategory;
private RecyclerView.LayoutManager mLayoutManager;
private Context context = RecyclerViewActivity.this;
private Activity activity = RecyclerViewActivity.this;
private CategoryAdapter categoryAdapter;
private CategoryClickListener categoryClickListener;
ArrayList<ArrayList<SubcategoryModel>> listData = new ArrayList<>();
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_recycler_view);
categoryClickListener = this;
getDummyData();
recyclerViewCategory = (RecyclerView) findViewById(R.id.recycler_view);
mLayoutManager = new LinearLayoutManager(context);
recyclerViewCategory.setHasFixedSize(true);
recyclerViewCategory.setLayoutManager(mLayoutManager);
categoryAdapter = new CategoryAdapter(context, listData, categoryClickListener);
recyclerViewCategory.setAdapter(categoryAdapter);
}
public void getDummyData() {
for (int i = 0; i < 10; i++) {
ArrayList<SubcategoryModel> subCategoryData = new ArrayList<>();
subCategoryData.add(new SubcategoryModel("Sub category 1", false));
subCategoryData.add(new SubcategoryModel("Sub category 2", false));
subCategoryData.add(new SubcategoryModel("Sub category 3", false));
subCategoryData.add(new SubcategoryModel("Sub category 4", false));
subCategoryData.add(new SubcategoryModel("Sub category 5", false));
listData.add(subCategoryData);
}
}
private void showDialog(ArrayList<SubcategoryModel> listSubcategory) {
try {
final Dialog dialog = new Dialog(context);
dialog.setCancelable(true);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().getAttributes().windowAnimations
= R.style.Animation_AppCompat_DropDownUp;
dialog.setContentView(R.layout.dialog_subcategory);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = dialog.getWindow();
lp.copyFrom(window.getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
window.setAttributes(lp);
RecyclerView recyclerViewSubcategory = (RecyclerView) dialog.findViewById(R.id.recycler_view_subcategory);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(context);
recyclerViewSubcategory.setHasFixedSize(true);
recyclerViewSubcategory.setLayoutManager(mLayoutManager);
SubCategoryAdapter adapter = new SubCategoryAdapter(context, listSubcategory);
recyclerViewSubcategory.setAdapter(adapter);
dialog.show();
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void categoryClick(int position) {
showDialog(listData.get(position));
}
}
public class CategoryAdapter extends RecyclerView.Adapter<CategoryAdapter.CustomViewHolder> {
private ArrayList<ArrayList<SubcategoryModel>> listData;
private Context context;
private CategoryClickListener categoryClickListener;
public CategoryAdapter(Context context, ArrayList<ArrayList<SubcategoryModel>> listData, CategoryClickListener categoryClickListener) {
this.listData = listData;
this.context = context;
this.categoryClickListener = categoryClickListener;
}
@Override
public CategoryAdapter.CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_category_view, parent, false);
CategoryAdapter.CustomViewHolder viewHolder = new CategoryAdapter.CustomViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(final CategoryAdapter.CustomViewHolder holder, int position) {
try {
holder.textViewCategory.setText("Category "+(position+1));
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public int getItemCount() {
return (null != listData ? listData.size() : 0);
}
class CustomViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private TextView textViewCategory;
public CustomViewHolder(View itemView) {
super(itemView);
itemView.setOnClickListener(this);
textViewCategory = (TextView) itemView.findViewById(R.id.textViewCategory);
}
@Override
public void onClick(View v) {
categoryClickListener.categoryClick(getAdapterPosition());
}
}
}
class SubCategoryAdapter extends RecyclerView.Adapter<SubCategoryAdapter.CustomViewHolder> {
private ArrayList<SubcategoryModel> listData;
private Context context;
public SubCategoryAdapter(Context context, ArrayList<SubcategoryModel> listData) {
this.listData = listData;
this.context = context;
}
@Override
public SubCategoryAdapter.CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_subcategory_view, parent, false);
SubCategoryAdapter.CustomViewHolder viewHolder = new SubCategoryAdapter.CustomViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(final SubCategoryAdapter.CustomViewHolder holder, int position) {
try {
SubcategoryModel subCategory = listData.get(position);
holder.textViewSubCategory.setText(subCategory.name);
if(subCategory.isChecked)
{
holder.checkBox.setChecked(true);
}else{
holder.checkBox.setChecked(false);
}
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public int getItemCount() {
return (null != listData ? listData.size() : 0);
}
class CustomViewHolder extends RecyclerView.ViewHolder {
private TextView textViewSubCategory;
private CheckBox checkBox;
public CustomViewHolder(View itemView) {
super(itemView);
textViewSubCategory = (TextView) itemView.findViewById(R.id.textViewSubCategory);
checkBox = (CheckBox) itemView.findViewById(R.id.checkbox);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
listData.get(getAdapterPosition()).isChecked=isChecked;
}
});
}
}
}
public class SubcategoryModel {
String name;
boolean isChecked;
public SubcategoryModel(String name, boolean isChecked)
{
this.name = name;
this.isChecked = isChecked;
}
}
public interface CategoryClickListener {
public void categoryClick(int position);
}
activity_recycler_view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:scrollbars="none">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
dialog_subcategory
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view_subcategory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:scrollbars="none">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
row_category_view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:padding="10dp">
<TextView
android:id="@+id/textViewCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"/>
</LinearLayout>
row_subcategory_view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/textViewSubCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000"/>
</LinearLayout>
.