最近都没有时间来更新我的博客,主要是在项目中遇到一些比较棘手的问题需要解决,今天我就把我解决的难题写了个Demo出来与大家一起分享,最终达到火种通讯录联系人界面的效果 。
在这次代码编写当中 , 我主要用到了来显示友好提示
在对数组进行排序的时候,我们可以用 .sort()方法轻松实现按字母顺序排序 。
另外在实现点击字母后让滚动到以该字母开头的相应位置效果时,我们要用到如下方法:
一个是通过int ([] a, key) 方法来获得该字母出现的Item在中的位置,
另一个就是 list.(); 来让List指向对应位置的Item 。
当你对这些方法都有所了解了以后 , 下面我们开始设计我们的Demo 。
我们先建立一个名为的工程,然后就是代码部分了:
第一步,在res/的main.xml中我们来设置中显示上下层显示的效果,其实就是一个相对布局 。
Java代码
"":="":="":=""> :id="@+id/list":="" :="" /> :id="@+id/" :="30dip":="":t="true":p="true":ght="true":="@null"/>
第二步,我们在中建一个.xml,这是用来通过显示友好提示的 。
Java代码
"" :="70sp" :="#" :="70dip" :="70dip" :="10dip" :="" />
第三步 , 是.xml用来设置中Items的布局 。
Java代码
xmlns:="":="":="":=""> "@+id/" :="" :="" :="20dip" :="10dip" :="@/":="gone">:="":="":=""> :id="@+id/order":="":="60dip":="15dip":="left":="2"/> :id="@+id/":="":="":="60dip":="15dip":="2"/>
文章插图
第四步 , 是一个.xml用来显示右边覆盖在上的的Items
Java代码
xmlns:="":="":="":="20dip">
第五步,我们建一个名为的类,然后就是实现功能的代码了,里面有非常详尽的注释,大家慢慢看吧 。
Java代码
.; .util.; .util.; .app.; ..; ..; .os.; .os.; .view.; .view.View; .view.; .view.; .view..; ..; ..; ..; ..; ..; ..; ..; ...; ...; /** *@.罗 * */,{ /**.*/; ; ; erlay;//用来放在中显示提示字符r; ; e;//滚动的状态,; @(tate){ super.(); (R..main); =().from(this).(R..,null); //默认设置为不可见 。
.(View.); //设置 .=.(., .,.., //设置为无焦点状态 ..|.., //半透明效果 .); =()(.); .(,lp);=(); =(); .sort(,.ER);//大小写不敏感=(); for(inti=0;i=0?[idx].(0):''; =[].(0); //将小写字符转换为大写字符 =.(); =.(); if(!=){ .w.(View.); .w.(.()); }else{ //此段代码不可缺:实例化一个后,会被多次赋值并且只有最后一次赋值的是正确.w.(View.GONE); } ; } }(,, ,){ //以中间的为标准项来显示 。
.(.([+(>>1)].(0)).()); } (,){ this.=; if(==..){ .(); //提示延迟1.5s再消失 .(,1500); }else{ .(View.); } } k(,,, ){=(()view).().(); .(s); .(View.); .(); //提示延迟1.5s再消失 .(,1500);=(,s);//接收返回值if(!=-1){ .(View.);//防止点击出现的与滚动出现的冲突list.();//让List指向对应位置的Item} } //将选中的py与的首字符进行匹配并返回对应字符串在数组中的位置arch([],){ for(inti=0;iif(s.(""+[i].(0))){//不区分大小写; } } -1;}(){ super.(); //将删除 。
【高仿android通讯录--右边字母排序功能】 .(View.); .(); }/**在这里我们将字符串打乱,且含有大小写开头不等*/[]={"","","","","", "Acorn","","","'lPitu","Airag","","", "","","","","","", "","","","","","", "","","","","Autun","","", "","","","","","","Banon","Barry'", "","","","","","","", "","","","","","","", "","","","Bleud'","","", "","","Blue","","", "()","","","()", "","","","","","'", "","","","Bra","","","", "","","","Brick","Brie","", "","-","Brin","Brind'Amour","Brind'Amour","()", "","","","-","", "","()","","'Anjou","", "","Butte","","(Innes)","","","Caboc","", "","","","","","","", "","","","","", "","","'Est","","","", "","","","","","", "'","","","","","", "","","","","","","", "Derby","","","","","Colby","","Comte", "","","","","","","", "","()","","","", "","","","","","", "","","","","","","", "Curd","","","","","()", "Danbo","","","","","", "Derby","","","","","","", "","","","","", "","","","","","", "()","Edam","","","","", "","","Esrom","","ie","'", "","","Feta","Feta()","Figue","","Fin-de-", "","Finn","","","","","", "","","","","'Aosta", "","","","'","", "","","","","", "","","","","","","", "avoie","","","","Fynbo", "","","","'","", "'Ail","","","","","","", "","","","","Gouda","Goutu","","", "","r","Grana","","","'", "-","","","Greve","","","","", "","()","-","","","", "","","","Herve","","", "","","","","","Iled'Yeu", "","","","","","","", "","","","","","","","", "mBrie","","","","", "L'","L''","","","","", "Lajta","","","","Lappi","","","","", "","","","","","","","", "","'Orb","","","", "","","","","", "","","","","","","Mahon","", "","","","Manur","","","","", "","","","","()","","", "","Meira","","","","", "()","","","","","Mine-", "","Mixte","Molbo","","","MontD'","", "","","","","", "","()","",",", "","","Murol","","","","","", "()","Niolo","","","","","", "","","ddar","Orla","","", "Ossau-Iraty","","","P'","","","", "","","()","","'", "","","","","Paved'", "Paved'Auge","","","","es", "","","","","", "","","","","Petit-", "","","Piora","","", "","","'Ane","","Pontl'","", "Port-Salut","","-Saint-","","","","-Jean", "","","()","","","Quark", "Quark()","","-Vents","","", "--","","","", "","()","","","", "","","","","","","", "","","","","","","", "","()","","","","","","", "","","","Roule","","","", "","","","Saga","","","Saint-", "Saint-","Saint-","","Samso","","","","Sardo", "","","","","","","Selva","Serat", "ar","","","","","Siraz", "","","","","","", "","","","St.","", "","","","","","","Swiss"}; []={"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"}; }
- vivox7联系人设置在哪 vivox7的联系人设置在哪
- Android 9
- 苹果阻止通讯录以外号码来电对方怎么知道 苹果阻止通讯录以外号码
- Android TextView设置自定义字体
- Android--简易倒计时
- qq怎么关闭可能认识的人通讯录 QQ怎么关闭可能认识的人
- Android打造专有hook,让不规范的代码扼杀在萌芽之中
- Android图片加载机制
- 苹果手机sim卡通讯录导出到手机
- Android WebView 保持登录问题