日期:2014-05-20  浏览次数:20770 次

使用J2ME在手机中如何实现按照汉字的拼音排序?
谢谢!

------解决方案--------------------
应该要写比较器的吧。
j2se里面是的
------解决方案--------------------
自己做个排好序的码表,然后根据这个码表写个比较器就完了。官方的实现也不过如此。
------解决方案--------------------
我也想知道,自己写个码表,那是大多的字库啊?
不知道有没有获得一个汉字的拼音的开源包?

------解决方案--------------------
unicode编码以前研究过,给你一个程序去研究吧.
汉字转化为全拼的算法

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Set;

/**
*
汉字转化为全拼
*
JDK版本: 1.4
*/

public class CnToSpell {
private static LinkedHashMap spellMap = null;
public static boolean isEn = false;
static {
if (spellMap == null) {
spellMap = new LinkedHashMap(400);
}
initialize();
}

private CnToSpell() {
}

private static void spellPut(String spell, int ascii) {
spellMap.put(spell, new Integer(ascii));
}

private static void initialize() {
spellPut( "a ", -20319);
spellPut( "ai ", -20317);
spellPut( "an ", -20304);
spellPut( "ang ", -20295);
spellPut( "ao ", -20292);
spellPut( "ba ", -20283);
spellPut( "bai ", -20265);
spellPut( "ban ", -20257);
spellPut( "bang ", -20242);
spellPut( "bao ", -20230);
spellPut( "bei ", -20051);
spellPut( "ben ", -20036);
spellPut( "beng ", -20032);
spellPut( "bi ", -20026);
spellPut( "bian ", -20002);
spellPut( "biao ", -19990);
spellPut( "bie ", -19986);
spellPut( "bin ", -19982);
spellPut( "bing ", -19976);
spellPut( "bo ", -19805);
spellPut( "bu ", -19784);
spellPut( "ca ", -19775);
spellPut( "cai ", -19774);
spellPut( "can ", -19763);
spellPut( "cang ", -19756);
spellPut( "cao ", -19751);
spellPut( "ce ", -19746);
spellPut( "ceng ", -19741);
spellPut( "cha ", -19739);
spellPut( "chai ", -19728);
spellPut( "chan ", -19725);
spellPut( "chang ", -19715);
spellPut( "chao ", -19540);
spellPut( "che ", -19531);
spellPut( "chen ", -19525);
spellPut( "cheng ", -19515);
spellPut( "chi ", -19500);
spellPut( "chong ", -19484);
spellPut( "chou ", -19479);
spellPut( "chu ", -19467);
spellPut( "chuai ", -19289);
spellPut( "chuan ", -19288);
spellPut( "chuang ", -19281);
spellPut( "chui ", -19275);
spellPut( "chun ", -19270);
spellPut( "chuo ", -19263);
spellPut( "ci ", -19261);
spellPut( "cong ", -19249);
spellPut( "cou ", -19243);
spellPut( "cu ", -19242);
spellPut( "cuan ", -19238);
spellPut( "cui ", -19235);