Android imitation wechat address book search example (matching Pinyin, letters, index position)

preface:

Imitate the wechat address book search function to find the matching contact through Chinese characters or Pinyin initials and display the matching location

1: Look at the renderings first

Alphabetic index

Search match

2: Functional analysis

1: Chinese character to Pinyin

Pinyin 4J and tinypinyin are commonly used to convert Chinese characters into Pinyin in the address book (the first character should consider the multi tone character of the last name). Pinyin 4J has powerful functions and contains tone multi tone characters. Tinypinyin can execute quickly and occupy less memory. If it is only a simple match to the address book, tinypinyin is recommended to be used. The usage is also very simple, and will not be described in detail here

Pinyin Class

2: Define index bar a~z, # control

Itemdecoration cooperates with recyclerview to achieve the stickyheader effect. This effect is very common and will not be described in detail

3: Fast matching according to the converted Pinyin

Search matching is the core. The following matching principles have priority. If a match is successful, the following matching principles will not be implemented

a: Match the original characters and find out the matching start position and end position. If there is Chinese matching, the following Pinyin matching principle will not be implemented

b: Match the first letter of single character Pinyin (for example, "you Xiaochen" can match y, x, C, YX, Xc, yxc)

c: Match the Pinyin of all characters, and the Pinyin of the first matching position must be consistent (e.g. "you Xiaochen", which must match the beginning of Yo, you, Xi, Xia, Xiao, CH, Che, Chen, etc., such as yo, youx, Youxi, Youxiao, XiaoC, xiaoch, Xiaochen, etc.)

Finally, the source code is attached https://github.com/youxiaochen/ContactList

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>