Android-based Recyclerview for a highlighted search list

Source: Internet
Author: User

This should be Recycleview's fourth article, Recycleview is really a new generation of Darling can do so many things.

Reprint Please specify the author Androidmsky and the original link
http://blog.csdn.net/AndroidMsky/article/details/53306657

This article GitHub: Welcome to Star
Https://github.com/AndroidMsky/SearchView

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

Believe this effect a lot of projects will use, today talk about the use of Recycleview to achieve him, Bo master this article positioning the primary article , perhaps because this is really very simple, so I want to speak more details so that the novice can also see understand.

The food is going to be started, and what ingredients should we prepare?

1. A recyclerview or a ListView or other control that can display multiple item (main dry goods)
2. Figure out the real-time monitoring of edittext
3. Make a textview appear in different colors
4. How to cross Adpter to find the key value in TextView (that is, highlight the string)

When you get through these four technical points, if you do not achieve this effect, then you can say that your current study is too inflexible, not ingenious. If you see the effect immediately think of these four technical points you have a certain project organization ability. Next we will analyze this four ingredients.
1.RecyclerView hesitation here is relatively simple can use the Recyclerview, but the author has been in the packaging good recyclerview so also used in my previous package to achieve if the recyclerview is not familiar with the portal to send you away:
http://blog.csdn.net/androidmsky/article/details/52922348

2.EditText fact input listening is actually an excuse each time the character in the Editext changes, the interface is recalled:

Textwatcher Textwatcher =NewTextwatcher () {@Override         Public void beforetextchanged(Charsequence charsequence,intIintI1,intI2) {}@Override         Public void ontextchanged(Charsequence charsequence,intIintI1,intI2) {}@Override         Public void aftertextchanged(Editable Editable) {        }    };

Popping a registered interface, OnTextChanged is the way we want it:

        editMobile.addTextChangedListener(textWatcher);

3.textview display different colors, in fact, there are many ways to achieve, the most stupid is to use two or three textview to achieve the highlight color next to each other, however this is not scientific, we use stringformatutil such a tool class to achieve the highlight color.

StringFormatUtil spanStr3 = new //分别是上下文,原串,key,高亮颜色。StringFormatUtil(mContext, data.name,                mkey, R.color.blue).fillColor();            customerHolder.tvName.setText(spanStr3.getResult());

4.Adapter how to Know key.
It is possible to pass in the construction method:

public CustomerCampanySearchAdapter(List<Customer>listString key) {        super(list);        = context;        = key;        this.list=list;    }

All right, 4 ingredients, we're ready.
The cooking logic is as follows:

1. Register the production of all classes.

2. Re-construct the Customercampanysearchadapter in the callback interface of the real-time monitoring edittext to pass in the new key value.

 Public void Showcustomer(list<customer> List, String key) {if(List = =NULL|| List.size () = =0)return;        Customerlist.clear ();        Customerlist.addall (list); adapter =NewCustomercampanysearchadapter (CustomerList, This, key);        Superrecyclerview.setadapter (adapter);        Superrecyclerview.showdata (); Adapter.setonitemclicklistener (NewBaserecycleradapter.onitemclicklistener () {@Override             Public void Onitemclick(View view,intPositionLongID) {//}        }); }

3. Change the Highlight key value of the TextView in the Onbindviewholder method in Customercampanysearchadapter.

@Override public void Onbindviewholder (baserecyclerviewholder holder, int position, final Customer data) {Custo Merholder Customerholder = (customerholder) holder;Customerholder. Tvname. SetText(Data. Name);Stringformatutil SPANSTR3 = new Stringformatutil (Mcontext, data. Name, Mkey, R. Color. Blue). FillColor();if (SPANSTR3! = null) Customerholder. Tvname. SetText(SPANSTR3. GetResult());else Customerholder. Tvname. SetText(Data. Name);}

The effect of such a perfect realization, but also advocates in the analysis must be calm, first of all to understand what effect you want, then you need what sub-effect, and then how these sub-effects string up to achieve the final effect.

This article GitHub: Welcome to Star
Https://github.com/AndroidMsky/SearchView

Welcome to add the author of the self-development of the Android Exchange Group: 308372687

Bo Master original without permission shall not be reproduced, reproduced must investigate

—————————————————————————————
Recommended by the author: Android Custom view scrolling data display
http://blog.csdn.net/androidmsky/article/details/53009886
Recyclerview dropdown Refresh page load performance optimization and Gilde mate loading trilogy
http://blog.csdn.net/androidmsky/article/details/53115818
Create an enterprise-class network request Framework collection RETROFIT+GSON+MVP
http://blog.csdn.net/androidmsky/article/details/52882722
Android phone automatically pick up QQ video second change camera
http://blog.csdn.net/androidmsky/article/details/53066441 —————————————————————————————

Android-based Recyclerview for a highlighted search list

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.