2012-10-29 17 views
16

Ho un edittext e uno spinner. Quando tocco l'editaxt appare la tastiera, dopo aver completato il montaggio del testo tocco la freccia a discesa dello spinner ma la tastiera non scompare automaticamente. Per favore dammi una soluzione. Ho provato questo codicecome nascondere la tastiera virtuale al tocco di uno spinner

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

Questo è il 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 è automaticamente scompaiono quando l'EditText perso attenzione .. quindi può essere voi utilizzando qualsiasi altra proprietà per EditText, mostrare il proprio XML e codice –

+0

@CapDroid ho postato il mio xml, si prega di controllare e fammi sapere dove mi ho torto. – swati

risposta

31

provare questo codice, spero che lavorerà per voi.

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 buona :) buon divertimento –

0

Prova questo:

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

questo è il codice che ho usato per impostare la spinner.Can mi suggerisci dove dovrei usare il tuo codice ArrayAdapter dataAdapterage = new ArrayAdapter (questo, \t \t R.layout.spinner_adapter, ageValue); dataAdapterheight.setDropDownViewResource (android.R.layout.simple_spinner_dropdown_item); mDateOfBirth.setAdapter (dataAdapterage); – swati

+0

dovresti scrivere questo nell'ascoltatore di clic per la filatrice –

0

Se si hanno Spinner e EditText un'attività allora questo è il problema si è sensazione andando di sicuro,

chiamata onTouchListener sul filatore e dentro che prendono il riferimento del vostro EditText e nascondere 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; 
     } 
    }) ; 
Problemi correlati