반응형
android : Done 키를 누르면 소프트 키보드가 작업을 수행합니다.
EditText가 있습니다. 텍스트를 입력 한 후 사용자 Done
가 소프트 키보드 의 키를 누르면 버튼 클릭 이벤트에서도 구현 한 일부 검색 작업을 직접 수행해야합니다.
이 시도
editText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId==EditorInfo.IME_ACTION_DONE){
//do something
}
return false;
}
});
이 시도
DONE 및 RETURN 모두에 대해 작동합니다 .
EditText editText= (EditText) findViewById(R.id.editText);
editText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER
|| actionId == EditorInfo.IME_ACTION_DONE) {
// Do your action
return true;
}
return false;
}
});
를 잡아서 KeyEvent
키 코드를 확인합니다. FLAG_EDITOR_ACTION
Enter 키가 "next"또는 "done"으로 자동 레이블 지정된 IME에서 오는 Enter 키를 식별하는 데 사용됩니다.
if (event.getKeyCode() == KeyEvent.FLAG_EDITOR_ACTION)
//your code here
두 번째 방법
myEditText.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
int result = actionId & EditorInfo.IME_MASK_ACTION;
switch(result) {
case EditorInfo.IME_ACTION_DONE:
// done stuff
break;
case EditorInfo.IME_ACTION_NEXT:
// next stuff
break;
}
}
});
이 시도
이것은 키보드에 Enter 기호 또는 다음 화살표 기호가 표시되는지 여부에 관계없이 두 조건에서 작동합니다.
YourEdittextName.setOnEditorActionListener(new TextView.OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
{
if(actionId== EditorInfo.IME_ACTION_DONE||actionId==EditorInfo.IME_ACTION_NEXT)
{
//Perform Action here
}
return false;
}
});
if u r facing red line then do this... import Keyevent and EditorInfo by pressing alt+enter then all the errors remove it will properly.......
반응형
'Nice programing' 카테고리의 다른 글
Visual Studio 편집기가 파일 하단을지나 스크롤을 중지하도록하는 방법은 무엇입니까? (0) | 2020.11.09 |
---|---|
Bin Path는 어떻게 얻습니까? (0) | 2020.11.09 |
앱이 전체 화면을 요구하지 않는 한 출시 스토리 보드 또는 xib를 제공해야합니다. (0) | 2020.11.09 |
Angular 2-이미지 URL이 유효하거나 손상되었는지 확인 (0) | 2020.11.09 |
컬렉션에서 항목을 제거하는 가장 좋은 방법 (0) | 2020.11.09 |