제가 님이 올리신 코드를 기반으로 테스트 해보면 별문제 없이 잘 동작합니다. 님 소스랑 비교해 보세요. 일부 클래스 이름 등은 다를 수 있습니다.
Parent Adapter
public class RegisteredHealthLogAdapter extends RecyclerView.Adapter<RegisteredHealthLogViewHolder> {
private List<String> items = new ArrayList<>();
public RegisteredHealthLogAdapter(List<String> items) {
this.items = items;
}
@NonNull
@Override
public RegisteredHealthLogViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.health_registered_add, parent, false);
return new RegisteredHealthLogViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull RegisteredHealthLogViewHolder holder, int position) {
String title = items.get(position);
List<ChildItem> childItems = new ArrayList<>();
childItems.add(new ChildItem("SET", "0", "0"));
childItems.add(new ChildItem("SET", "1", "1"));
childItems.add(new ChildItem("SET", "2", "2"));
ChildAdapterData childAdapterData = new ChildAdapterData(title, childItems);
holder.bind(childAdapterData);
}
@Override
public int getItemCount() {
return items.size();
}
}
public class RegisteredHealthLogViewHolder extends RecyclerView.ViewHolder {
private final TextView textView;
private final Button button;
private final RecyclerView recyclerView;
private final HealthLogSetAdapter adapter;
public RegisteredHealthLogViewHolder(@NonNull View itemView) {
super(itemView);
textView = itemView.findViewById(R.id.registeredTextView);
button = itemView.findViewById(R.id.addWeight);
recyclerView = itemView.findViewById(R.id.todayLogRectyclerView);
adapter = new HealthLogSetAdapter(Collections.emptyList());
recyclerView.setAdapter(adapter);
}
public void bind(ChildAdapterData data) {
textView.setText(data.getTitle());
adapter.setItems(data.getChildItems());
}
}
//health_registered_add.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="16dp"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/registeredTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/addWeight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/add_weight" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/todayLogRectyclerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
</LinearLayout>
Child Adapter
public class HealthLogSetAdapter extends RecyclerView.Adapter<HealthLogSetViewHolder> {
private List<ChildItem> items = new ArrayList<>();
public HealthLogSetAdapter(List<ChildItem> items) {
this.items = items;
}
public void setItems(List<ChildItem> items) {
this.items = items;
notifyDataSetChanged();
}
@NonNull
@Override
public HealthLogSetViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.health_log_add_set, parent, false);
return new HealthLogSetViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull HealthLogSetViewHolder holder, int position) {
holder.bind(items.get(position));
}
@Override
public int getItemCount() {
return items.size();
}
}
public class HealthLogSetViewHolder extends RecyclerView.ViewHolder {
private TextView setTextView, weightTextView, repsTextView;
public HealthLogSetViewHolder(@NonNull View itemView) {
super(itemView);
setTextView = itemView.findViewById(R.id.setTextView);
weightTextView = itemView.findViewById(R.id.weightTextView);
repsTextView = itemView.findViewById(R.id.repsTextView);
}
public void bind(ChildItem item) {
setTextView.setText(item.getText1());
weightTextView.setText(item.getText2());
repsTextView.setText(item.getText3());
}
}
public class ChildItem {
private final String text1;
private final String text2;
private final String text3;
public ChildItem(String text1, String text2, String text3) {
this.text1 = text1;
this.text2 = text2;
this.text3 = text3;
}
public String getText1() {
return text1;
}
public String getText2() {
return text2;
}
public String getText3() {
return text3;
}
}
public class ChildAdapterData {
private final String title;
private final List<ChildItem> childItems;
public ChildAdapterData(String title, List<ChildItem> childItems) {
this.title = title;
this.childItems = childItems;
}
public String getTitle() {
return title;
}
public List<ChildItem> getChildItems() {
return childItems;
}
}
//health_log_add_set.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingVertical="8dp"
tools:context=".MainActivity">
<TextView
android:id="@+id/setTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/weightTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TextView
android:id="@+id/repsTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>