Android implements highlight search list based on recyclerview

Not much to say, let's look at the effect of today's implementation:

I believe this effect will be used in many projects. Today, I will talk about using recycleview to realize it. The blogger positioned this article as a primary article. Maybe because it is really simple, I want to be more detailed so that novices can understand it.

The meal is about to start. What ingredients should we prepare.

1. A recyclerview or listview or other controls that can display multiple items (main dry goods)

2. Find out the real-time monitoring of EditText

3. Make a textview appear in different colors

4. How to find the key value (i.e. highlighted string) in textview through adpter

When you get through these four technical points, if you can't achieve this effect, you can say that your current learning is too rigid and can't be used flexibly. If you see the effect and immediately think of these four technical points, it shows that you have a certain project organization ability. Next, let's analyze the four ingredients.

1. Recyclerview hesitates. It is relatively simple here. You can use the original sound recyclerview, but I have been using the encapsulated recyclerview, so I still use the encapsulated recyclerview. If you are not familiar with recyclerview, you can go through the portal: http://blog.csdn.net/androidmsky/article/details/52922348

2. EditText input monitoring is actually an excuse. Every time the characters in EditText change, this interface will be called back:

After registering the interface, ontextchanged is the method we want:

editMobile.addTextChangedListener(textWatcher);

3. Textview displays different colors. In fact, there are many ways to realize this. The most stupid thing is to use two or three textviews to realize the highlight color next to each other. However, this is not scientific. We use a tool class such as stringformatutil to realize the highlight color.

4. How does the adapter know the key.

Just pass in the construction method:

OK, four ingredients, we're ready

The cooking logic is as follows:

1. Registered production of all classes.

2. In the callback interface of real-time monitoring EditText, reconstruct the customercampanysearchadapter and pass in a new key value.

3. Change the highlighted key value of textview in the onbindviewholder method in customercampanysearchadapter.

In this way, the effect is perfectly realized. It is also advocated that everyone must be calm when analyzing. First, understand what effect you want, then what sub effects you need, and then how to string these sub effects to achieve the final effect.

GitHub: welcome to star https://github.com/AndroidMsky/SearchView

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of 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
分享
二维码
< <上一篇
下一篇>>