2012-10-29 129 views
16

我有一个edittext和一个微调。当我触摸编辑文本时,出现键盘,完成文本编辑后,我触摸微调器的下拉箭头,但键盘不会自动消失。请给我一些解决方案。 我想这个代码如何隐藏虚拟键盘触摸旋钮

InputMethodManager imm=(InputMethodManager)getApplicationContext().getSystemService(SetUpProfileActivity.this.INPUT_METHOD_SERVICE); 
     imm.hideSoftInputFromWindow(mDateOfBirth.getWindowToken(), 0); 

这是XML

<LinearLayout 
      android:id="@+id/outerlayout" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="10dp" 

      > 

      <TextView 
       android:id="@+id/name_view" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:text="@string/profile_name" 
       android:textColor="#ffffff" /> 

      <EditText 
       android:id="@+id/profile_name" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp" 
       android:background="@drawable/txtbox" 
       android:singleLine="true" /> 

      <TextView 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp" 
       android:text="@string/dateofbirth" 
       android:textColor="#ffffff" /> 

      <Spinner 
       android:id="@+id/dob" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="5dp" 
       android:background="@drawable/dropdown" /> 
+0

Softkeyboard自动消失的是当你的EditText失去焦点..所以可能是你使用任何其他财产的EditText,显示你的XML代码: –

+0

@CapDroid我已经发布我的XML,请让我知道我我错了。 – swati

回答

31

试试这个代码,我希望它会为你工作。

mSpinner.setOnTouchListener(new OnTouchListener() { 

      @Override 
      public boolean onTouch(View v, MotionEvent event) { 
       InputMethodManager imm=(InputMethodManager)getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE); 
       imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0); 
       return false; 
      } 
     }) ; 
+0

@swati好:)亲爱的亲爱的 –

0

试试这个:

// hide the keyboard if open 
      inputManager.hideSoftInputFromWindow(getParent().getCurrentFocus() 
        .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 
+0

这是我用来设置spinner.Can代码你建议我在哪里,我应该用你的代码ArrayAdapter dataAdapterage =新ArrayAdapter (这一点, \t \t R.layout.spinner_adapter,ageValue); dataAdapterheight.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mDateOfBirth.setAdapter(dataAdapterage); – swati

+0

你应该在spinner的点击监听器中写下这个 –

0

如果你在一个活动有微调和EditText上那么这样的问题,你是会觉得在您的微调和内部的肯定,

通话onTouchListener把你的EditText的参考和隐藏softkeyboard 。

mySpinner.setOnTouchListener(new View.OnTouchListener() { 

     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      InputMethodManager inputMethodManager=(InputMethodManager)getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE); 
      inputMethodManager.hideSoftInputFromWindow(mReuestBloodActNotes.getWindowToken(), 0); 
      return false; 
     } 
    }) ;