2012-11-12 42 views
4

本质上,我试图显示虚拟键盘和收集输入,而不使用可见的EditTextTextView。我知道toggleSoftInput可以用来做到这一点,但我需要使用showSoftInput,因为我想用TextWatcher来操纵输入。另外,我使用的引擎是C++,因此我试图尽可能少使用纯java代码,所以我避免了.xml文件。所以这里去...为什么不显示SoftInput显示虚拟键盘?

public class GameActivity extends Activity { 

    protected GameView view = null; 
    protected EditText editText; 

    protected void onCreate(Bundle bundle) 
    { 
     super.onCreate(bundle); 

     view = new GameView(this); 
     setContentView(view); 

     editText = new EditText(this); 
     editText.setCursorVisible(false); 
     editText.setFocusable(true); 
     editText.setFocusableInTouchMode(true); 
    } 

    public boolean showKeyboard() 
    { 
     JniApp.log("showKeyboard() in Java invoked!!!"); 

     editText.requestFocus(); 
     editText.requestFocusFromTouch(); 

     InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
     imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED); 
    } 

其中showKeyboard()是我的C++调用java。我已经检查过,以确保editText获得重点并且是。但是,showSoftInput返回false。任何帮助将不胜感激。

更新:经过一些调试后,看起来好像requestFocus返回true,但活动仍然表示view是当前焦点。

回答

0

也许试试.SHOW_IMPLICIT而不是.SHOW_FORCED?

你有没有在其他模拟器/设备上试过它可能与其他Android版本?