Home > Net >  recyclerView is not responding
recyclerView is not responding

Time:04-02

package com.crowthweb.newsin;

import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity; import androidx.recyclerview.widget.LinearLayoutManager;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    recyclerView.layoutManager = new LinearLayoutManager(MainActivity.this);

}

}

CodePudding user response:

You need to setAdapter to that RecyclerView. Then, it will work only. Also, don't forget to initialize the recyclerView first.

CodePudding user response:

You need an Adapter and a LayoutManager to visible RecyclerView

        RecyclerView recyclerView;
        MessageAdapter messageAdapter;
        LinearLayoutManager layoutManager;
        List<Message> messageList;    
        protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_chat);

        recyclerView  = findViewById(R.id.my_rycler_view);
        messageList = new Arraylist<>();
        messageAdapter = new MessageAdapter(this, messageList);
        layoutManager = new 
        LinearLayoutManager(this,RecyclerView.VERTICAL,false);
    
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(messageAdapter);
    }

CodePudding user response:

In xml :

   <androidx.recyclerview.widget.RecyclerView
        android:id="@ id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />

In java :

 binding.recyclerView.setAdapter(new MyAdapter(this, myList);
  • Related