2011-05-27 43 views
1

我有一個有兩個EditText的活動。如果在橫向模式下,我選擇了第一個EditText,則顯示的鍵盤有一個「下一個」按鈕,它應該允許我輸入第二個EditText。同樣,第二個EditText有一個「完成」按鈕,我想完成該活動。我如何處理這些按鈕的選擇?如何使用android橫向鍵盤按鈕?

回答

3

關於如何解決此問題的文檔相當少。我找到了一個很好的解決方案here。基本上,你可以爲每個EditTexts的添加IMEoption: 對於第一種:

 android:imeOptions="actionNext" 

對於第二個:

 android:imeOptions="actionDone" 

要在代碼中處理這些,嘗試這樣的事情:

EditText departureAddress, destinationAddress; 
departureAddress = (EditText)findViewById(R.id.departure); 
//Set the action of the "next" button to bring destinationAddress to focus 
destinationAddress(new OnEditorActionListener(){ 
@Override 
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
    if (actionId == EditorInfo.IME_ACTION_NEXT) { 
     destinationAddress.requestFocus(); 
    } 
    return true; 
} 
    }); 
    destinationAddress = (EditText)findViewById(R.id.destination); 
    //Set the action of the "done" button to handle the map query 
    destinationAddress.setOnEditorActionListener(new OnEditorActionListener(){ 
@Override 
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
    if (actionId == EditorInfo.IME_ACTION_DONE) { 
     //Handle map query 
    } 
    return true; 
} 
    });