Android 按中文首字母排序
2015-06-28 11:53
489 查看
按中文字母排序
使用https://github.com/belerweb/pinyin4j
/**
* 得到中文首字母缩写
*
* @param str
* @return
*/
public static String getPinYinHeadChar(String str) {
String convert = "";
for (int j = 0; j < str.length(); j++) {
char word = str.charAt(j);
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
if (pinyinArray != null) {
convert += pinyinArray[0].charAt(0);
} else {
convert += word;
}
}
return convert.toUpperCase();
}
public class Demo implements Serializable, Comparable<Demo>{
private String sortKey;
public String getSortKey() {
return sortKey;
}
public void setSortKey(String sortKey) {
this.sortKey = sortKey;
}
@Override
public int compareTo(Demo another) {
return this.getSortKey().compareTo(another.getSortKey());
}
}
使用https://github.com/belerweb/pinyin4j
/**
* 得到中文首字母缩写
*
* @param str
* @return
*/
public static String getPinYinHeadChar(String str) {
String convert = "";
for (int j = 0; j < str.length(); j++) {
char word = str.charAt(j);
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
if (pinyinArray != null) {
convert += pinyinArray[0].charAt(0);
} else {
convert += word;
}
}
return convert.toUpperCase();
}
public class Demo implements Serializable, Comparable<Demo>{
private String sortKey;
public String getSortKey() {
return sortKey;
}
public void setSortKey(String sortKey) {
this.sortKey = sortKey;
}
@Override
public int compareTo(Demo another) {
return this.getSortKey().compareTo(another.getSortKey());
}
}
相关文章推荐
- Android 压缩图片
- Android自定义View圆环带文字进度条
- 疯狂Android讲义(1b)-基于监听&回调的事件处理-小结
- Android之EventBus概述及源码解析(雷惊风)
- Android 使用集成过的SDK
- android hander如何避免内存泄露
- Android SQLite数据库之事务的学习
- Android线程机制——AsyncTask
- android屏幕适配建议
- android listview 消除滑动到底端或者顶端时的黑色阴影
- android SDK下载及中文API地址
- (android之安全)Android 无源码动态调试工具
- android 最大化 视频播放 横屏
- Android 对像保存到文件
- (android之安全)ANDROID应用与系统安全防御
- 【Android】图片资源的访问与网格式图片浏览器
- Android Studio走过的坑
- Android 旋转ImageView
- Android 自动化测试
- Android LinearLayout模拟ListView