2011-12-06 23 views
1

私はEnterキーを押したときに仮想キーボードを隠すのに以下のコードを使用していますが、隠れていません。もし誰かがこのことやコードの間違いを知っていたら、私に返答してください。仮想キーボードを隠す

package onchip.learning.smalltest; 

import android.app.Activity; 
import android.content.Context; 
import android.os.Bundle; 
import android.view.KeyEvent; 
import android.view.inputmethod.InputMethodManager; 
import android.widget.EditText; 
import android.widget.LinearLayout; 
import android.widget.TextView; 
import android.widget.TextView.OnEditorActionListener; 

public class SmallTest extends Activity { 
    EditText et; 

    /** Called when the activity is first created. */ 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     et = new EditText(this); 
     et.setLines(1); 
     et.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT)); 
     setContentView(et); 

     et.setOnEditorActionListener(new OnEditorActionListener() { 

      @Override 
      public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
       // TODO Auto-generated method stub 
       if(event.getKeyCode() == KeyEvent.KEYCODE_ENTER) { 
        InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.hideSoftInputFromInputMethod(et.getWindowToken(), 0); 
        return true; 
       } 
       return false; 
      } 
     }); 
    } 
} 

おかげ

+0

hideSoftInputFromWindow(et.getWindowToken(), 0)を使用するためにあなたがエミュレータでこれをテストしていますか? – Cata

+0

オンデバイスではない –

答えて

2

てみ代わりにhideSoftInputFromInputMethod()

+0

より貴方の仕事 –

+0

ようこそ! :) – Cata

0

使用この

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
関連する問題