[JavaME]如何确认用户连续按键指的是哪一个字符

有点像手机英文输入法中,按2一下代表a,连按两下代表b,连续三下代表c。
据说,你可以用timertask来做这件事情。

我的一个设想是(未曾代码试验过,错了请指出):

用户按键“1”,那么计数他按了多少下,根据他按的次数去你事先写好的数组中查到是哪一个字符。如果用户迟迟没有再按下去,那么到了一定时间,就应该确认他的输入了,timer呢就调用confirmCharacter()。

String[] values = {".,1","abc","def"... ...};
 
keyPressed(keyCode) {
  int index = keyCode - KEY_NUM0;
  if(index == lastindex) charselected++;
  else lastindex = index;
   // here reset the key confirmation timer
 
   tempInputString+=values[index].char(charselected);
}
 
//When timer gets triggered, it calls this method
void confirmCharacter() {
    inputString = tempInputString;
    lastindex = -1;
}

你可能感兴趣的:([JavaME]如何确认用户连续按键指的是哪一个字符)