2017-05-04 13 views
1

저는 EditText가 있고 입력 유형은 textNoSuggestions입니다. 또한키보드의 텍스트 패드를 숫자 패드로 변경하십시오.

<android.support.design.widget.TextInputLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="16dp" 
        android:layout_marginRight="16dp" 
        android:layout_marginTop="5dp"> 

        <EditText 
         android:id="@+id/firstName" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:ems="10" 
         android:hint="Name" 
         android:inputType="textNoSuggestions" /> 
       </android.support.design.widget.TextInputLayout> 

나는 키보드의 입력 type.This를 변경하는 하나 개의 버튼과 버튼의 onclick 방법을 시도했다 그것이 가능 버튼을 클릭했을 때의 키보드 '입력 유형을 변경하기 위해 소스

final Button changeKeyboard = (Button) dialog.findViewById(R.id.change_keyboard); 
    changeKeyboard.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      firsName.setRawInputType(InputType.TYPE_CLASS_NUMBER); 

     } 
    }); 

입니다 키보드가 보이고 있습니까? 어떻게 내 문제를 해결할 수 있습니다 모두 덕분에

+0

및 SO 검색 한 후, 나는 비슷한 질문을 찾을 수 없습니다 . 대답을 찾는 것이 행운이다. – Vucko

답변

0

세트는 setInputType()이 아닌 setTransformationMethod()입니다. 그래서 뭔가 같은 : 이것에

firsName.setRawInputType(InputType.TYPE_CLASS_NUMBER); 

("T"와 firstName을, 당신의 XML을 이름) : 코드 변경에

firstName.setTransformationMethod(numberTransformationMethod.getInstance()); 
+0

어쩌면 당신은 내 대답하세요 (키보드가 표시되고있는 경우) 버튼 클릭으로 @jai khambhayta – BekaKK

0

또한

firstName.setRawInputType(InputType.TYPE_CLASS_NUMBER); 

, 당신을 X는 int이며 firstName.setInputType (x)의을 할 수 있습니다 : 긍정적 같이 setInputType를 호출 키보드를 변경할 수 있습니다 1 일 것 (영숫자); 2 (숫자) 또는 3 (전화 같은).

편집 :

당신은 당신의 활동이 전화 키보드를 숨길 수 있습니다

는 :

public static void hideKeyboard(Activity activity) { 
    InputMethodManager imm = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE); 
    //Find the currently focused view, so we can grab the correct window token from it. 
    View view = activity.getCurrentFocus(); 
    //If no view currently has focus, create a new one, just so we can grab a window token from it 
    if (view == null) { 
     view = new View(activity); 
    } 
    imm.hideSoftInputFromWindow(view.getWindowToken(), 0); 
} 
이 고유 한 문제처럼 보인다
+0

그것은 그 : 그 변수를 이름에 오타의 가능성이 아니에요을 숫자 패드와 키보드의 문자 패드를 변경하려면 이해하지 못했다, 그것은 원인이 그랬다면 컴파일 타임 오류. 아니면 NullPointer ID는 좋지 않았다합니다. – Vucko

+0

키보드, 숨길 그래서 – BekaKK

+0

을 @statosdotcom 숨길을 변경하고 다시 올릴 때 그것은 단지 일하고있어. – statosdotcom

0
firsName.setInputType(InputType.TYPE_CLASS_NUMBER);