2012-09-24 77 views

回答

3
//Clicking on the text box  

    edittext.setOnClickListener(new OnClickListener(){ 
     public void onClick(View v) { 
     InputMethodManager imm = (InputMethodManager) getSystemService(
       INPUT_METHOD_SERVICE); 
     imm.showSoftInput(getCurrentFocus().getWindowToken(), //some flag here); 
     } 

    }); 

    //Being inside the box and pressing a key 
    edittext.setOnKeyListener(new OnKeyListener() { 
     public boolean onKey(View v, int keyCode, KeyEvent event) { 
      //If the event is a key-down event on the "enter" button 
      //If enter is pressed while inside the textbox 
      if ((event.getAction() == KeyEvent.ACTION_DOWN) && 
       (keyCode == KeyEvent.KEYCODE_ENTER)) { 

        InputMethodManager imm = (InputMethodManager) getSystemService(
         INPUT_METHOD_SERVICE); 
        //Example of hiding keyboard inside enter pressed check 
        imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0); 

........