티스토리 뷰

먼저, EditText 의 커스텀 키보드를 제작하는 방법입니다. ↓
EditText 커스텀 키보드 제작



키보드를 만들었다면 해당 메소드를 구현합니다.



1. 커서 위치부터 한칸 지우기. 

커스텀 키보드의 BackSpace 등 개발자가 지우길 원하는 버튼을 눌렀을 경우의 이벤트.

public void backBTN(EditText et){
    // EditText 커서 position을 구합니다.
    int selection = et.getSelectionStart();

    // 커서 position 이 0이라면, nullpointer exception occur.. 종료합니다.
    if(selection == 0){
        return;
    }
    
    // position을 기준으로 두 구간 분리.
    // ex) "123456"에서 커서가 3 뒤에 있다면 "123"과 "456"으로 ��눕니다.
    //     여기서 3을 지우고 "12"와 "456"을 붙여줍니다.
    phoneno = phoneno.substring(0, selection - 1) + phoneno.substring(selection, phoneno.length());
    et.setText(phoneno);

    // editText position을 ��재 position�� 한칸 앞으로 이동시킵니다.
    et.setSelection(selection-1);
}



2. 커서 위치부터 한글자 추가하기.


/**
	 * ��재 커서 위��에서 한글자(add) 추가
	 * @param phoneno
	 */
	public void inputPad(EditText et, String add){
		// ��재 커서위��를 구한다.		
		int selection = et.getSelectionStart();

		phoneno = phoneno.substring(0, selection) + add + phoneno.substring(selection, phoneno.length());
		
		et.setText(phoneno);
		setCursorPosition(selection + 1);
	}



공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함