2016-08-25 65 views
0

我一直試圖在加載片段(包含edittext)時自動顯示鍵盤並將焦點放在編輯文本上。第一次加載片段時軟件鍵盤不會出現

我已經嘗試使用:

 editTextPrice.requestFocus(); 
    InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); 
    imgr.showSoftInput(getView(), InputMethodManager.SHOW_IMPLICIT); 

但是,這並不工作,我第一次加載片段。焦點被設置,我可以看到光標,但沒有出現鍵盤。如果我關閉這個片段並重新添加,它就會起作用。

如果嘗試從post()到推遲處理程序到onResume等等。

有沒有人有一個想法可能會導致這種情況發生?

在此先感謝。

問候

+0

試圖把editTextPrice代替getView(); – Muddz

+0

@Patric你是如何實現這個功能的? –

回答

0
android:focusable="true" 
android:focusableInTouchMode="true" 

而且

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