2016-09-16 42 views
1

您好在我的片段中使用自定義鍵盤視圖。當過用戶輕敲編輯文本我shwoing這種觀點Android:在調用onPause()時隱藏或銷燬視圖

insideEdit.setOnTouchListener(new OnTouchListener() { 
       public boolean onTouch(View v, MotionEvent event) { 

        mKeyboardViewTolerance = new CustomKeyboard(getActivity(), R.id.keyboardviewtolerance, R.xml.keyboard_layout); 
        mKeyboardViewTolerance.showCustomKeyboard(insideEdit); 
        insideEdit.setInputType(InputType.TYPE_NULL); 
        return false; 
       } 
      }); 

當過用戶切換到其他片段,並配到相同的片段和水龍頭的觀點並沒有渲染的EditText。我可以看到視圖在那裏,但視圖在屏幕上不可見。

我試圖隱藏它的onPause(),但仍然認爲不可見

@Override 
    public void onPause() { 
     if(mKeyboardViewTolerance != null && mKeyboardViewTolerance.isCustomKeyboardVisible()){ 

       mKeyboardViewTolerance.hideCustomKeyboard(); 
      } 
} 

回答

0

嘗試使用上的EditText焦點監聽。

0

使用此代碼,它會解決你的問題:在我的showkeyboard使用相同的()文攻的EditText

View view = this.getCurrentFocus(); 
if (view != null) { 
    InputMethodManager mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
      mInputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), 0); 
} 
+0

已經...... \t公共無效showCustomKeyboard(視圖v){ \t \t mKeyboardView.setVisibility(View.VISIBLE); \t \t mKeyboardView.setEnabled(true); \t \t \t如果(V!= NULL) \t \t \t((InputMethodManager)mHostActivity \t \t \t \t \t .getSystemService(mHostActivity.INPUT_METHOD_SERVICE)) \t \t \t \t \t .hideSoftInputFromWindow(v.getWindowToken() 0); \t} – hari86

+0

可以共享您的自定義鍵盤類的導入包名稱 –

+0

package com.ts.in.android.oring.activity; – hari86