package com.fq.app.adapter;
import com.testcontact.R;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.SectionIndexer;
import android.widget.TextView;
public class ListViewAdp extends BaseAdapter implements SectionIndexer {
private Context mContext;
private String[] cityName;
static int i;
static String[] first;
public ListViewAdp(Context mContext, String[] parentData) {
this.mContext = mContext;
this.cityName = parentData;
}
@Override
public int getCount() {
return cityName.length;
}
@Override
public Object getItem(int position) {
return cityName[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final String nickName = cityName[position];
i = position;
ViewHolder viewHolder = null;
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(
R.layout.contact_item, null);
viewHolder = new ViewHolder();
viewHolder.tvCatalog = (TextView) convertView
.findViewById(R.id.contactitem_catalog);
viewHolder.tvNick = (TextView) convertView
.findViewById(R.id.contactitem_nick);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
String catalog = converterToFirstSpell(nickName).substring(0, 1);
viewHolder.tvCatalog.setText(catalog);
if (position == 0) {
viewHolder.tvCatalog.setVisibility(View.VISIBLE);
viewHolder.tvCatalog.setText(catalog);
} else {
String lastCatalog = converterToFirstSpell(cityName[position - 1])
.substring(0, 1);
if (catalog.equals(lastCatalog)) {
viewHolder.tvCatalog.setVisibility(View.GONE);
} else {
viewHolder.tvCatalog.setVisibility(View.VISIBLE);
viewHolder.tvCatalog.setText(catalog);
}
}
// viewHolder.ivAvatar.setImageResource(R.drawable.default_avatar);
viewHolder.tvNick.setText(cityName[position]);
return convertView;
}
static class ViewHolder {
TextView tvCatalog;
// ImageView ivAvatar;
TextView tvNick;
}
@Override
public int getPositionForSection(int section) {
for (int i = 0; i < cityName.length; i++) {
String l = converterToFirstSpell(cityName[i]).substring(0, 1);
char firstChar = l.toUpperCase().charAt(0);
if (firstChar == section) {
return i;
}
}
return -1;
}
@Override
public int getSectionForPosition(int position) {
return 1;
}
@Override
public Object[] getSections() {
return null;
}
public static String converterToFirstSpell(String chines) {
String pinyinName = "";
char[] nameChar = chines.toCharArray();
HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat();
defaultFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE);
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
for (int i = 0; i < nameChar.length; i++) {
if (nameChar[i] > 128) {
try {
pinyinName += PinyinHelper.toHanyuPinyinStringArray(
nameChar[i], defaultFormat)[0].charAt(0);
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
} else {
pinyinName += nameChar[i];
}
}
return pinyinName;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
类似手机通讯录的ListView列表,右侧有A-Z的26个字母索引,点击相应的字母就会跳到相应的字母对应的城市,并且屏幕中间有字母提示,点击单个item,也会有相应的点击效果和提示【特别注意,1:如果程序运行出错,请记得勾选jar包,右键单击工程-Properties-Java Build Path-Oder and Export-pinyin4j-2.5.0.jar,2:手机记得连接网络】
资源推荐
资源详情
资源评论
收起资源包目录
City_A-Z.rar (70个子文件)
bin
classes.dex 134KB
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
mm_listitem_pressed.9.png 192B
mm_text_bg_trans.9.png 305B
default_avatar.9.png 2KB
mm_listitem_simple.9.png 188B
show_head_toast_bg.9.png 2KB
nav_page.9.png 216B
drawable-mdpi
ic_launcher.png 2KB
TestContact.apk 170KB
jarlist.cache 120B
dexedLibs
annotations-8e9cdcdf20a1efdb7fb4577b6bb912e7.jar 943B
pinyin4j-2.5.0-32130df082d03fd7bc58012b5c307cf7.jar 141KB
pinyin4j-2.5.0-04334af6532a676b711207a965e257d7.jar 141KB
annotations-103804336a6de050d2005df44c72ad7c.jar 943B
pinyin4j-2.5.0-60bb2c9b996409aa6d82b2f6972737d4.jar 141KB
classes
com
testcontact
BuildConfig.class 339B
R$layout.class 458B
R$id.class 534B
R$drawable.class 670B
R$attr.class 331B
R.class 555B
R$string.class 418B
R$style.class 591B
fq
app
MainActivity.class 3KB
MainActivity$2.class 1KB
MainActivity$1.class 2KB
bean
ProvinceBean.class 790B
MainActivity$1$1.class 2KB
common
Domxml.class 4KB
SideBar.class 4KB
adapter
ListViewAdp.class 4KB
ListViewAdp$ViewHolder.class 463B
util
Pinyin_Comparator.class 866B
PingYinUtil.class 2KB
resources.ap_ 20KB
City_A-Z.apk 170KB
AndroidManifest.xml 1005B
res
drawable-ldpi
ic_launcher.png 2KB
drawable-hdpi
ic_launcher.png 4KB
mm_listitem_pressed.9.png 139B
mm_text_bg_trans.9.png 188B
default_avatar.9.png 1KB
mm_listitem_simple.9.png 133B
show_head_toast_bg.9.png 3KB
nav_page.9.png 184B
drawable-xhdpi
drawable
mm_listitem.xml 496B
values
strings.xml 188B
styles.xml 3KB
drawable-mdpi
ic_launcher.png 3KB
layout
contact_item.xml 1KB
list_position.xml 353B
main.xml 915B
assets
gen
com
testcontact
BuildConfig.java 157B
R.java 2KB
proguard.cfg 1KB
.settings
org.eclipse.core.resources.prefs 107B
src
com
fq
app
bean
ProvinceBean.java 433B
MainActivity.java 4KB
common
Domxml.java 2KB
SideBar.java 3KB
adapter
ListViewAdp.java 4KB
util
PingYinUtil.java 2KB
Pinyin_Comparator.java 413B
.project 844B
.classpath 537B
project.properties 360B
AndroidManifest.xml 1005B
libs
pinyin4j-2.5.0.jar 184KB
共 70 条
- 1
__________刮開看
- 粉丝: 0
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于C语言的系统服务框架.zip
- (源码)基于Spring MVC和MyBatis的选课管理系统.zip
- (源码)基于ArcEngine的GIS数据处理系统.zip
- (源码)基于JavaFX和MySQL的医院挂号管理系统.zip
- (源码)基于IdentityServer4和Finbuckle.MultiTenant的多租户身份认证系统.zip
- (源码)基于Spring Boot和Vue3+ElementPlus的后台管理系统.zip
- (源码)基于C++和Qt框架的dearoot配置管理系统.zip
- (源码)基于 .NET 和 EasyHook 的虚拟文件系统.zip
- (源码)基于Python的金融文档智能分析系统.zip
- (源码)基于Java的医药管理系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页