我試圖以edittext的形式從用戶收集數據。用戶將輸入一個字符串,然後單擊一個按鈕來執行以下操作:我如何忽略/使用回車android
public String encode(String s){
String result = "";
String element = "";
HashMap<String, String> translate = new HashMap<String, String>();
//initializing translate
translate.put("A",".-");
translate.put("B","-...");
translate.put("C","-.-.");
translate.put("D","-..");
translate.put("E",".");
translate.put("F","..-.");
translate.put("G","--.");
translate.put("H","....");
translate.put("I","..");
translate.put("J",".---");
translate.put("K","-.-");
translate.put("L",".-..");
translate.put("M","--");
translate.put("N","-.");
translate.put("O","---");
translate.put("P",".--.");
translate.put("Q","--.-");
translate.put("R",".-.");
translate.put("S","...");
translate.put("T","-");
translate.put("U","..-");
translate.put("V","...-");
translate.put("W",".--");
translate.put("X","-..-");
translate.put("Y","-.--");
translate.put("Z","--..");
translate.put("1",".----");
translate.put("2","..---");
translate.put("3","...--");
translate.put("4","....-");
translate.put("5",".....");
translate.put("6","-....");
translate.put("7","--...");
translate.put("8","---..");
translate.put("9","----.");
translate.put("0","-----");
s = s.toUpperCase();
for(int i=0; i < s.length();i++)
{
element = (String) translate.get(String.valueOf(s.charAt(i)));
if(element == null)
result += String.valueOf(s.charAt(i));
else
result += element;
}
return result;
}
如果用戶點擊鍵盤,它將插入一個換行符/回車手機上的「Enter」鍵。我如何解決這個問題,以便它添加一個新行?我不介意使用回車作爲發佈命令來改變edittext區域的焦點的方法,但如果不是這樣,那麼就根本不允許它被使用。
非常感謝! – 2012-02-24 20:53:09