2011-01-06 47 views
2

我正在構建一個應用程序,用於在各種格式之間轉換緯度和經度 。我的佈局已完成,但我目前 面臨的挑戰是:將文本從一個EditText框複製到同一活動中的另一個文字,逐個字符

爲度值,爲用戶在EditText1的值,我想 它在EditText2複製,因爲他們打字,實時,個性 爲字符。我已經戰勝了自己了嘗試OnTouchListener, onKeyboardActionListener等

後來,他們在輸入我將執行對分,秒, 小數部分的計算。由於學位字段不 不需要計算我只是試圖在現在跨多個EditText框複製用戶值 。

摘要: 在EditText1中鍵入字符時捕獲字符 將EditText1捕獲的字符置於EditText2中。

任何幫助將不勝感激。

麥克墨菲

回答

1

我沒有測試過,但我發現addTextChangedListener():

EditText firstEditText = (EditText)findViewById(R.id.firstEditText); 
firstEditText.addTextChangedListener(new TextWatcher(){ 
    public void afterTextChanged(Editable s){ 
     String c = s.toString(); // read Content 
     ((EditText)findViewById(R.id.secondEditText)).setText(c); // copy to #2 
    } 
    public void beforeTextChanged(CharSequence s, int start, int count, int after){ } 
    public void onTextChanged(CharSequence s, int start, int before, int count){ } 
}); 

http://groups.google.com/group/android-developers/browse_thread/thread/eba1a2ea7d3a2828?fwc=1

+0

太謝謝你了!這個伎倆。我試圖通過在Activity中實現TextWatch來實現,並且無法讓它正常工作。 – RotorDroid 2011-01-07 01:14:13

相關問題