yoop****
30
2021-09-26 17:04:04 작성 2021-09-26 17:08:31 수정됨
2
104

안드로이드 리사이클러뷰 onbindviewholder 반응없음


안드로이드에서 리사이클러뷰 구현 중에 
onbindviewholder가 반응이 없습니다..


상황은 네비게이션바를 열었을 때 채팅방에 있는 사람 목록이 나오게 하는 것입니다.


(다른 곳은 println 찍으면 나오는데 onbindviewholder만 나오지 않음)

실행화면


chatting_drawer.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/chatting_drawer"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="right"
android:background="#FFFEE6"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"

android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="대화상대"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:textSize="30dp"
/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/chatting_drawer_recyclerview"/>

</LinearLayout>
<Button
android:layout_marginLeft="10dp"
android:layout_gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/group_room_exit"
android:text="채팅방 나가기"/>
</LinearLayout>

item_chatroom_people.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginBottom="10dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:orientation="horizontal"

>

<!--프로필 사진-->
<ImageView
android:id="@+id/memeber_profile"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginRight="5dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_gravity="left">
<!--방이름-->
<TextView
android:id="@+id/memeber_nickname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="사람 이름"
android:textSize="25dp"
android:textColor="#000000"/>


</LinearLayout>
</LinearLayout>

<!--구분선-->
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginHorizontal="10dp"
android:background="#000000"/>

</LinearLayout>
드로워 안에 리사이클러뷰 연결 부분

group_chat_hbg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawerLayout.openDrawer(drawerView);
groupmember_recyclerView = (RecyclerView)findViewById(R.id.chatting_drawer_recyclerview);
groupmember_recyclerView.setAdapter(new GroupMemberRecyclerViewAdapter());
groupmember_recyclerView.setLayoutManager(new LinearLayoutManager(Group_MessageActivity.this));

}
});
리사이클러뷰어댑터
class GroupMemberRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

List<UserModel> userModels;


Intent intent = getIntent();
String chat_masterUid = intent.getStringExtra("chat_masterUid");
String room_name = intent.getStringExtra("room_name");
String option_selector = intent.getStringExtra("option_selector");

public GroupMemberRecyclerViewAdapter() {

userModels = new ArrayList<>();


FirebaseDatabase.getInstance().getReference().child("users").child(chat_masterUid).child("my_chatting_list").child("그룹 채팅방").child(room_name).child("chatroomuid").addListenerForSingleValueEvent(new ValueEventListener() {

@Override
public void onDataChange(@NonNull @NotNull DataSnapshot snapshot) {

String chatroomuid1 = snapshot.getValue().toString();

FirebaseDatabase.getInstance().getReference().child("chatting_room").child(option_selector).child("Room_Name").child(room_name).child("talk").child(chatroomuid1).child("users").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull @NotNull DataSnapshot snapshot) {

for (DataSnapshot item : snapshot.getChildren()) {
members.add(item.getKey());

}


for(int i=0; i < members.size(); i++) {
int finalI = i;
FirebaseDatabase.getInstance().getReference().child("users").child(members.get(i)).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull @NotNull DataSnapshot snapshot) {

userModels.add(snapshot.getValue(UserModel.class));


}

@Override
public void onCancelled(@NonNull @NotNull DatabaseError error) {

}
});


}

}


@Override
public void onCancelled(@NonNull @NotNull DatabaseError error) {

}
});
}

@Override
public void onCancelled(@NonNull @NotNull DatabaseError error) {

}


});







}

@NonNull
@NotNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull @NotNull ViewGroup parent, int viewType) {

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_chatroom_people, parent, false);


return new GroupMemberViewHodler(view);


}

@Override
public void onBindViewHolder(@NonNull @NotNull RecyclerView.ViewHolder holder, int position) {

GroupMemberViewHodler groupMemberViewHodler = ((GroupMemberViewHodler)holder);

System.out.println(userModels.get(position).nickname);

groupMemberViewHodler.group_member_nickname.setText(userModels.get(position).nickname);

Glide.with(holder.itemView.getContext())
.load(userModels.get(position).imageUri)
.apply(new RequestOptions().circleCrop())
.into(groupMemberViewHodler.group_member_profile);


}

@Override
public int getItemCount() {
return 0;
}

private class GroupMemberViewHodler extends RecyclerView.ViewHolder {

public TextView group_member_nickname;
public ImageView group_member_profile;


public GroupMemberViewHodler(View view) {
super(view);

group_member_nickname = (TextView)view.findViewById(R.id.memeber_nickname);
group_member_profile = (ImageView)view.findViewById(R.id.memeber_profile);

}
}


}

0
  • 답변 2

  • HSYE
    214
    2021-09-27 11:13:51
    @Override
    public int getItemCount() {
    return 0;
    }

    가 userModels의 크기가 아닌 0을 리턴하고 있습니다.

  • yoop****
    30
    2021-09-27 20:48:12

    그래서 고쳐봤으나 그게 문제가 아니었나봅니다...

  • 로그인을 하시면 답변을 등록할 수 있습니다.