Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize Recycleview suspension sticky head plus right alphabet navigation by Android

Shulou Source: shulou.com Published: 2022-06-03 09:38:40 11月15日 Update

This article mainly introduces Android how to achieve Recycleview suspension sticky head plus right letter navigation, the article is very detailed, has a certain reference value, interested friends must read it!

The idea of realization is:

The linkage on the right can be achieved using the scrollToPositionWithOffset method of adapter in recycyeview. On the left is recycleview. The city data returned by the backend is of this type:

The copy code is as follows:

{"returnCode": 1, "returnMsg": "Operation succeeded", "data": [{"startWord": "A", "trainCityList": [{"cityId": 531, "cityName": "Ang Xi", "code": null}, {"cityId": 2137

I did a layer of encapsulation.

1. Create an entity class to encapsulate the subscript and city name:

Public class ContactModel {private String index; private String name; public ContactModel (String name) {this.index = NewFirstLetterUtil.getFirstLetter (name); this.name = name;} public String getIndex () {return index;} public String getName () {return name;}}

two。 Encapsulate the data returned by the server:

List contacts = new ArrayList (); for (int item0)

Tags: Right letter code data encapsulation header stickiness navigation content city article adapter adaptation success subscript two value side interest name Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Technology macOS MariaDB Redmi