0

我知道他們有100個關於這個的帖子,不知何故它不適合我。 我得到了一個EditText,當我「觸摸」那個盒子時,鍵盤必須出現。如何在edittext集中時顯示軟鍵盤

這一切我已經試過:

public void onClick(View v) { 
      EditText Edit_perceel_nr2 = (EditText)findViewById(R.id.Perceel_nr2);; 
      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
      imm.hideSoftInputFromWindow(Edit_perceel_nr2.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 

public void onClick(View v) { 
      EditText Edit_perceel_nr2 = (EditText)findViewById(R.id.Perceel_nr2);; 
      InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
      imm.hideSoftInputFromWindow(Edit_perceel_nr2.getWindowToken(), 0); 

public void onClick(View v) { 

      EditText Edit_perceel_nr2 = (EditText)findViewById(R.id.Perceel_nr2);; 
      ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(Edit_perceel_nr2, 0); 

public void onClick(View v) { 

      EditText Edit_perceel_nr2 = (EditText)findViewById(R.id.Perceel_nr2);; 
      ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(Edit_perceel_nr2, InputMethodManager.SHOW_IMPLICIT); 

我甚至試圖在清單中加入:

android:windowSoftInputMode="stateAlwaysVisible" 

但我無法讓它工作。 也許我忘了一些東西,但我現在沒有想法。 有人有更多的想法或解決方案?

這是我的EditText:

<EditText 
    android:id="@+id/Perceel_nr2" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:inputType="number" 
    android:text="text"> 
</EditText> 
+0

據我知道你並不需要做任何事情來顯示鍵盤。只需添加您的EditText並且不要爲它設置onClick! – caiocpricci2 2012-02-28 09:12:39

+0

哦,沒有onClick是一個按鈕,當我點擊一個按鈕,然後他必須做一些行動,這就是其中之一。 – Bigflow 2012-02-28 09:15:42

+0

你是如何創建你的編輯文本? – caiocpricci2 2012-02-28 09:16:35

回答

4

嘗試用這個..

EditText yourEditText= (EditText) findViewById(R.id.yourEditText); 
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT); 

,收u可以使用

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0); 
+0

啊,我是個盲人-.-,我使用'hideSoftInputFromWindow'而不是'showSoftInputFromWindow',我已經在這個問題上看了3個小時(喝咖啡的時間?) – Bigflow 2012-02-28 09:25:20

+0

我現在已經刪除了'InputMethodManager',並且它現在也能工作,現在也沒有強制鍵盤顯示代碼。 – Bigflow 2012-02-28 09:34:42

相關問題