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 that the effect of a lot of projects will be used, today talk about the use of Recycleview to achieve him, Bo master this article positioning 0 Basic , maybe because this is really easy, so I want to talk about the specific point so that the novice can also see understand.

We have to start the meal and we have to prepare the ingredients.

1. A recyclerview or a ListView or other control that displays multiple item (Basic 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. Assuming that this effect cannot be achieved, then you can say that your study is too rigid and not ingenious. Suppose you see the effect immediately think of these four technical points indicating that you have a certain project organization ability. Next we will analyze this four ingredients.
1.RecyclerView hesitation here is simpler to use the Recyclerview of the soundtrack. But the author has been using the encapsulated good recyclerview so also used in my previous package to achieve the assumption of Recyclerview is not familiar with the portal to send you away:
http://blog.csdn.net/androidmsky/article/details/52922348

2.EditText fact input listening, in fact, is an excuse. This interface is called back every time a character in the Editext changes:

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) {        }    };

A note of the interface. OnTextChanged is the way we want it:

        editMobile.addTextChangedListener(textWatcher);

3.textview shows different colors, in fact, there are a lot of implementations, the stupidest thing 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.
In the construction method to pass in will be able to:

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

All right, 4 ingredients, we're ready.
Cooking logic such as the following:

1. Register the production of all classes.

2. In the callback interface of real-time monitoring edittext again constructs the Customercampanysearchadapter 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 is so perfectly fulfilled. We also advocate that you must be calm when analyzing. First of all to understand what you want to effect, after that is what you need to effect, and then how these sub-effects are strung together to achieve the effect finally.

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 consent may not be reproduced. Reprint must investigate

—————————————————————————————
Author Recommendation: Android to define the view scrolling data display
http://blog.csdn.net/androidmsky/article/details/53009886
Recyclerview drop-down refresh paging load performance optimization and Gilde fit Load 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 to take the initiative to 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.