E / RecyclerView: адаптер не подключен; пропуская макет, при использовании RecyclerView адаптер - PullRequest
0 голосов
/ 25 апреля 2020

Хорошо, позвольте мне сказать это заранее ... Для этой проблемы я искал более 28 похожих вопросов о переполнении стека ... потратил / потратил более 2 дней, но все еще не смог отладить, в чем именно заключается проблема .. .

Все идет хорошо, показывает, что сборка прошла успешно, но макет никогда не заполняется элементом представления (как ожидается от адаптера) ...

В Logcat он показывает:

E/RecyclerView: No adapter attached; skipping layout
E/RecyclerView: No adapter attached; skipping layout

(дважды)

Любая помощь будет признательна, так как никакая подсказка в другом ответе не поможет мне ... после попытки в течение многих часов, я сейчас сдаюсь ... (это сообществу разработчиков)

Вот мой код ... Активность,

    List<ChatNode> chatNodeList = new ArrayList<>();
    RecyclerView channels = findViewById(R.id.listviewChannel);
    RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
    channels.setLayoutManager(layoutManager);
    //channels.setItemAnimator(new DefaultItemAnimator());
    //channels.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));


    ChatNode chatNode1 = new ChatNode("Hare", "This was last chat", "2:13", "3", "1");
    chatNodeList.add(chatNode1);
    ChatNode chatNode2 = new ChatNode("P 11", "This was last chat", "2:13", "3", "1");
    chatNodeList.add(chatNode2);
    ChatNode chatNode3 = new ChatNode("Q 12", "This was last chat", "2:13", "3", "1");
    chatNodeList.add(chatNode3);
    ChatListAdapter chatListAdapter = new ChatListAdapter(chatNodeList);

    channels.setAdapter(chatListAdapter);
    //chatListAdapter.notifyDataSetChanged();

Это мой ChatListAdapter

public class ChatListAdapter extends RecyclerView.Adapter<ChatListAdapter.MyViewHolder> {

private List<ChatNode> chatNodes;

public class MyViewHolder extends RecyclerView.ViewHolder {
    TextView name, lastchat, lastchattime, chatunread;
    ImageView dp;
    MyViewHolder(@NonNull View itemView) {
        super(itemView);
        name = itemView.findViewById(R.id.lastChat_Name);
        lastchat = itemView.findViewById(R.id.lastChat_Message);
        lastchattime = itemView.findViewById(R.id.lastChat_MessageDate);
        chatunread = itemView.findViewById(R.id.chat_unread);
        dp = itemView.findViewById(R.id.dp);
    }
}

ChatListAdapter(List<ChatNode> chatNodes) {
    this.chatNodes = chatNodes;
}

@Override
public ChatListAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.e2_fragment_chat_list_item, parent, false);

    return new MyViewHolder(itemView);
}

@Override
public void onBindViewHolder(ChatListAdapter.MyViewHolder holder, int position) {
    ChatNode chatNode = chatNodes.get(position);
    holder.name.setText(chatNode.getName());
    holder.lastchat.setText(chatNode.getLastchat());
    holder.lastchattime.setText(chatNode.getLastchattime());
    holder.chatunread.setText(chatNode.getChatunread());
    //holder.dp.setBackground(chatNode);
}

@Override
public int getItemCount() {
    return chatNodes.size();
}

}

Класс ChatNode

public class ChatNode {
String name, lastchat, lastchattime, chatunread, dp;

public ChatNode() {
}

public ChatNode(String name, String lastchat, String lastchattime, String chatunread, String dp) {
    this.name = name;
    this.lastchat = lastchat;
    this.lastchattime = lastchattime;
    this.chatunread = chatunread;
    this.dp = dp;
}

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

public String getLastchat() {
    return lastchat;
}

public void setLastchat(String lastchat) {
    this.lastchat = lastchat;
}

public String getLastchattime() {
    return lastchattime;
}

public void setLastchattime(String lastchattime) {
    this.lastchattime = lastchattime;
}

public String getChatunread() {
    return chatunread;
}

public void setChatunread(String chatunread) {
    this.chatunread = chatunread;
}

public String getDp() {
    return dp;
}

public void setDp(String dp) {
    this.dp = dp;
}

}

Файл макета

<LinearLayout
            android:id="@+id/channel"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <TextView
                android:id="@+id/textChannel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Channel"/>

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/listviewChannel"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

        </LinearLayout>

И это элемент списка

<?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="match_parent"
android:orientation="vertical"
android:padding="10dp">


<TextView
    android:id="@+id/tv_lastChat_Hidden"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:visibility="invisible" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:maxWidth="70dp"
        android:src="@drawable/dp_placeholder"
        android:paddingRight="3dp"
        android:paddingLeft="3dp"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/lastChat_Name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Full Name"
                android:textColor="#181717"
                android:textSize="25dp" />

            <TextView
                android:id="@+id/lastChat_MessageDate"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="right"
                android:text="Sent Date"
                android:textColor="#807474"
                android:textSize="20dp" />

        </LinearLayout>


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/lastChat_Message"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Message..."
                android:textColor="#807474"
                android:textSize="20dp" />

            <TextView
                android:id="@+id/chat_unread"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="2"
                android:gravity="right"
                android:textColor="#807474"
                android:textSize="20dp" />

        </LinearLayout>

    </LinearLayout>


</LinearLayout>

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...