Android contact last name prompt

Source: Internet
Author: User

When I use M1s, I feel that the last name of the contact in the prompt function is good. It is quite good to use. I made a simple function similar to this. The Code is as follows:

Package COM. FND. ui; import Java. util. arraylist; import Java. util. hashmap; import Java. util. list; import Java. util. map; import android. OS. bundle; import android. OS. handler; import android. app. activity; import android. content. context; import android. view. layoutinflater; import android. view. menu; import android. view. view; import android. view. viewgroup; import android. widget. abslistview; import android. widget. abslis Tview. onscrolllistener; import android. widget. listview; import android. widget. simpleadapter; import android. widget. textview; public class mainactivity extends activity {private textview TV _displayfamilyname; private listview lv_displaylinkman; private string [] linkmanstrings = new string [] {" Bing", "Liu ", "Zhang Fa", "Xu", "Mei", "Guo", "Wang", "Zhao", "Yan", "Ping San", "Khan ", "haoha", "new", "tu", "2", "3", "ba Jie", "monkey", "Zhong", "Rain", "fill ", "Zhang", "tu", "Liu", "Zhang", "Xu", "Mei", "Guo", "Wang", "Zhao", "Yan ", "ping", "Khan", "haoha", "new", "tu", "2", "3", "ba Jie", "monkey brother", "Zhong ", "Rain", "fill", "Zhang", "tu", "Liu", "Zhang", "Xu", "Mei", "Guo", "Wang ", "Zhao", "Yan", "ping", "Khan", "haoha", "new", "tu", "2", "3", "ba Jie ", "monkey brother", "Clock", "Rain", "fill in", "Zhang"}; private string firstdisplaystring; private Boolean isshowing; private string predisplaystring; private runnable displayrunnable; private int displaycount = 0; handler = New handler (); @ overrideprotected void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. activity_main); TV _displayfamilyname = (textview) findviewbyid (R. id. TV _displayfamilyname); lv_displaylinkman = (listview) findviewbyid (R. id. lv_displaylinkman); // Add a rolling listener lv_displaylinkman.setonscrolllistener (New displaylinkmanonscrolllistener () to the listview; List <Map <Str ING, Object> stringlist = new arraylist <Map <string, Object> (); For (string STR: linkmanstrings) {Map <string, object> map = new hashmap <string, Object> (); map. put ("name", STR); stringlist. add (MAP);} listitemadapter Lia = new listitemadapter (mainactivity. this, stringlist, R. layout. ll_lvdisplaylinkman_item, new string [] {"name"}, new int [] {R. id. TV _item}); lv_displaylinkman.setadapter (LIA); TV _display Familyname. setvisibility (view. invisible); displayrunnable = new displayrunnable ();} final class displaylinkmanonscrolllistener implements onscrolllistener {// stores the position of the top-level item of the current screen in listview. Private int firstvisibleitem = 0; @ overridepublic void onscroll (abslistview view, int firstvisibleitem, int visibleitemcount, int totalitemcount) {This. firstvisibleitem = firstvisibleitem;} @ overridepublic void onscrollsta Techanged (abslistview view, int scrollstate) {Switch (scrollstate) {Case onscrolllistener. scroll_state_idle: // when the slider stops, // extracts the last name (item in the middle of the current screen) firstdisplaystring = linkmanstrings [firstvisibleitem + displaycount/2]. substring (0, 1); If (! Isshowing &&! Firstdisplaystring. equals (predisplaystring) {TV _displayfamilyname.setvisibility (view. visible); isshowing = true;} TV _displayfamilyname.settext (firstdisplaystring); // remove the runnablehandler from the current message queue. removecallbacks (displayrunnable); // Add the new message queue runnablehandler. postdelayed (displayrunnable, 2000); break ;}}@ overridepublic Boolean oncreateoptionsmenu (menu) {getmenuinflater (). inflate (R. menu. activity_main, menu ); Return true;} final class displayrunnable implements runnable {@ overridepublic void run () {isshowing = false; TV _displayfamilyname.setvisibility (view. invisible) ;}} final class listitemadapter extends simpleadapter {layoutinflater minflater; List <Map <string, Object> stringlist; Public listitemadapter (context, list <Map <string, object> stringlist, int resource, string [] From, int [] to) {super (cont EXT, stringlist, resource, from, to); minflater = layoutinflater. from (context); this. stringlist = stringlist;} @ overridepublic int getcount () {return Super. getcount () ;}@ overridepublic object getitem (INT position) {return Super. getitem (position) ;}@ overridepublic long getitemid (INT position) {return Super. getitemid (position) ;}@ overridepublic view getview (INT position, view convertview, viewgroup parent) {Viewholder holder; If (convertview = NULL) {convertview = minflater. inflate (R. layout. ll_lvdisplaylinkman_item, null); holder = new viewholder (); holder. name = (textview) convertview. findviewbyid (R. id. TV _item); convertview. settag (holder);} else {holder = (viewholder) convertview. gettag ();} system. out. println ("position:" + position); system. out. println ("stringlist size:" + stringlist. size (); int lv_he Ight = lv_displaylinkman.getheight (); int item_height = convertview. getheight (); system. out. println ("lv_height:" + lv_height); system. out. println ("item_height:" + item_height); // calculates the number of listview items displayed on the screen of the mobile phone if (item_height! = 0) {displaycount = lv_height/item_height;} holder. name. settext (string) stringlist. get (position ). get ("name"); Return convertview ;}} static class viewholder {textview name ;}}

The above only implements very simple functions. If you are interested, you can implement a wealth of functions.

Related Article

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.