I want to create a custom adapter
for my list view. Is there any article which can walk me through how to create one and also explain how it works?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
This is a class I had used for my project. You need to have a collection of your items which you want to display, in my case it's
<Item>
. You need to overrideView getView(int position, View convertView, ViewGroup parent)
method.R.layout.itemlistrow
defines the row of theListView
.In the
MainActivity
defineListView
like this,Google has an example called EfficientAdapter, which in my opinion is the best simple example of how to implement custom adapters. http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List14.html @CommonsWare has written a good explanation of the patterns used in the above example http://commonsware.com/Android/excerpt.pdf
check this link, in very simple via the
convertView
, we can get the layout of a row which will be displayed in listview (which is theparentView
).using the position, you can get the objects of the
List<Item>
.after that we'll have to set the desired details of the object to the identified form widgets.
then it will return the constructed view which will be attached to the
parentView
(which is aListView
/GridView
).Here is the complete walk through to create a custom adapter for list view step by step -
https://www.caveofprogramming.com/guest-posts/custom-listview-with-imageview-and-textview-in-android.html
Data Model
Array Adapter
Main Activity
row_item.xml
A more compact example of a custom adapter (using list array as my data):
And this is how to use it: