RecyclerView displays only one item, although there are more.

adapter class

public class ContentAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private List<Article> articles;// TODO: нужно получать отсортированный list private Context context; private String TAG = "contentActivity"; public ContentAdapter(List<Article> articles, Context context) { this.articles = articles; this.context = context; } public class ArticleListHolder extends RecyclerView.ViewHolder{ TextView textView; public ArticleListHolder(View itemView) { super(itemView); textView = (TextView) itemView.findViewById(R.id.contentAdapterTextView); } } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { return new ArticleListHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.content_adapter_view, parent, false)); } @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { Article article = articles.get(position); ((ArticleListHolder) holder).textView.setText(article.getFullTitle()); ((ArticleListHolder) holder).textView.setOnClickListener(view -> { Intent intent = new Intent(context, ArticleActivity.class); intent.putExtra(Article.ORDER_NUMBER, article.getOrderNumber()); context.startActivity(intent); }); } @Override public int getItemCount() { return articles.size(); } } 

activation class

 public class ContentActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_content); RecyclerView recView = (RecyclerView)findViewById(R.id.contentRecView); recView.setLayoutManager(new LinearLayoutManager(this)); recView.setAdapter(new ContentAdapter(new LinkedList<Article>(((MyApplication)getApplication()).getArticles().values()),this)); Button menuButton =(Button) findViewById(R.id.contentMenuButton); menuButton.setOnClickListener(view -> startActivity(new Intent(this, ContentActivity.class))); } } 

ContentAdapterView.xml

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/contentAdapterTextView"/> </LinearLayout> 

activity_content.xml

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="ru.ckdigital.guideforpokemongo.ContentActivity" android:orientation="vertical"> <Button android:id="@+id/contentMenuButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_centerInParent="true" android:layout_gravity="center_horizontal" android:text="menu"/> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_alignParentTop="true" android:layout_above="@id/menuButton" android:requiresFadingEdge="vertical" android:id="@+id/contentRecView"/> </RelativeLayout> 
  • 3
    Scroll tried the list? In your markup for the element height = match_parent, it will stretch each element to full screen. Try changing to wrap_content. - Yura Ivanov
  • show how to add items. it is necessary to understand whether RecyclerView is updated - dramf
  • @dramf, the problem is solved, Yura correctly suggested, all my carelessness)) - JJoe

0