Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use RecyclerView in Android

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of how to use RecyclerView in Android, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this article on how to use RecyclerView in Android. Let's take a look at it.

First define a class Abc

Public class Abc {private String name;private int imageid;public Abc (String name,int iamgeid) {this.name=name;this.imageid=imageid;} public String getname () {return name;} public int getimageid () {return imageid;}}

Then prepare the adapter

Public class AbcAdapter extands RecyclerView.Adapter {private List M. public class ViewHolder extands RecyclerView.ViewHolder {ImageView abcimage;TextView abctext;public class ViewHolder (View view) {super (view); abcimage= (ImageView) findViewByid (R.id.XXX); abctext= (TextView) findVieByid (R.id.XX);} public AbcAdapter (Listabc) {mendabc;} public ViewHolder onCreateViewHolder (ViewGroup parent,int Viewtype) {View view=LayoutInflate.from (parent.getContext ()). } public ViewHolder onBindViewHolder (ViewHolder holder int position) {Abc abc=m.get (position); holder.iamge.setImageResource (abc.getimage); holder.name=setText (abc.gettext);} public int getItemCount () {return m.size ();}}

Finally, in MainActivity

XXX// loads data, and custom functions load data that need to be displayed in the function: RecyclerView recycler= (RecyclerView) findViewByid (R.id.XXX); LinearLayoutManager LayoutManager= new LinearLayoutManager (thsi); recycler.setLayoutmanager (layoutmanager); AbcAdapter dapter= new AbcAdapter (m); / / m is a collection, and a set recyclerView.setAdapter (adapter) should be defined above; this is the end of the article on "how to use RecyclerView in Android". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use RecyclerView in Android". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report