开发者

after to close a dialog, the keyboard do not dissappear

hello i have an activity and i call a dialog from it. When the dialog appears i write something in an edittext and i click in the save button... the problem is that after to close the dialog and comeback to the activity the keyboard remains there¡¡

i have tried to do this solutions:

a) in the layout (xml):

android:imeOptions="actionDone"

b) in the layout (xml):

android:focusable="true" 
android:focusableInTouchMode="true" 

c) in the manifest:

android:windowSoftInputMode="stateHidden"

but this do not work...the keyboard do not dissappear after to dismiss the dialog.

some clue please to solve my problem?

my dialog code:

public class DialogCreamodListas extends Dialog
implements OnClickListener 
{
    static EditText etxLISTArecep;
    static EditText etxPRESUPUESTOrecep;
    ImageView mImageViewImagen1;
    ImageView mImageViewImagen2;
    Button btnAceptar;
    Context mContext;
    static Long ID_LISTA;
    static DbAdapter mDbHelper; 

    public DialogCreamodListas(Context context, long ID_LISTA, DbAdapter mDbHelper){    
            super(context);
            mContext = context;
            LayoutInflater inflater = LayoutInflater.from(mContext);
            final View view = inflater
                    .inflate(R.layout.dialogcreamodlist, null);
            setContentView(view);
            DialogCreamodListas.ID_LISTA = (long) ID_LISTA;
            DialogCreamodListas.mDbHelper = mDbHelper; 

            this.setTitle("Crea o modifica una lista");
            mImageViewImagen1 = (ImageView) this.findViewById(R.id.image1);
            mImageViewImagen1.setImageResource(R.drawable.mascarrito);
            mImageViewImagen2 = (ImageView) this.findViewById(R.id.image2);
            mImageViewImagen2.setImageResource(R.drawable.edit2);
            etxLISTArecep = (EditText) findViewById(R.id.etxNombreLista);
            etxPRESUPUESTOrecep = (EditText) findViewById(R.id.etxPresupuesto);
            CargaInformacion(); 

            btnAceptar = (Button) findViewById(R.id.btn_aceptar);

            btnAceptar.setOnClickListener(this);    
    }

    private void CargaInformacion()
    {
            if(ID_LISTA != null && ID_LISTA != -1)
            {
                    Cursor Lista = mDbHelper.RecuperaRegistros(DbAdapter.TABLA_LISTAS,ID_LISTA);
                    ((Activity) mContext).startManagingCursor(Lista);
                    etxLISTArecep.setText(Lista.getString(Lista.getColumnIndexOrThrow(DbAdapter.LISTA)));
                    etxPRESUPUESTOrecep.setText(Lista.getString(Lista.getColumnIndexOrThrow(DbAdapter.PRESUPUESTO)));
            }
    }    

    public void onClick(View v) {
        if (v == btnAceptar) 
            {
                //AQUI RECUPERO LOS DATOS Y ALMACENO EN BBDD 
                GuardaDatos();
                CargarDatos();
                dismiss();
                return;
            }
        }   

        public static void GuardaDatos()
        {
            try
            {
            String[] Valores;

            if(ID_LISTA == null || ID_LISTA == -1)
            {
                Valores = new String[]{null,etxLISTArecep.getText().toString(),etxPRESUPUESTOrecep.getText().toString()};
                long id= mDbHelper.creaRegistro(DbAdapter.TABLA_LISTAS,Valores);
                if(id>0)
                {
                    ID_LISTA=id;
                }
            }
            else
            {   Valores = new String[]{ID_LISTA.toString(),etxLISTArecep.getText().toString(),etxPRESUPUESTOrecep.getText().toString()};    
                mDbHelper.actualizaRegistro(DbAdapter.TABLA_LISTAS,Valores);
            }   
            }
            catch(Exception E)
            {
                Log.e("EditaListas","Error: "+E);
            }
        }   

        public void CargarDatos()
        {
            if (this.mContext instanceof AdminListas)   
            {
                ((AdminListas) this.mContext).CargaDatos();
            }
            else
            {   
                Cursor ListaCursor=  mDbHelper.RecuperaRegistrosTabla(DbAdapter.VISTA_LISTAS);
                ((Activity) this.mContext).startManagingCursor(ListaCursor);        
                String[] Origen = new String[]{DbAdapter.LISTA,DbAdapter.PRESUPUESTO,DbAdapter.ARTICULOS,DbAdapter.DIFE开发者_C百科RENCIA};
                int [] Destino = new int[]{R.id.txvnombrelista,R.id.txvpresupuesto,R.id.txvarticulos,R.id.txvdiferencia};       
                SimpleCursorAdapter listas = new SimpleCursorAdapter(this.getContext(),R.layout.registrodetallelista,ListaCursor,Origen,Destino);       
                ((ListActivity) this.mContext).setListAdapter(listas);  
                }
        }


}


To manually close the soft keyboard you can do this:

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);

Where editText is the EditText your soft keyboard is currently interacting with.


to make dissapear the keyborad it is necesary to remove the follow parameter in the activity that call to your dialog in the manifest

android:windowSoftInputMode...

i had this that is supposed that hide the keyboard

android:windowSoftInputMode="stateHidden"

but when i have removed the entire line it works¡¡¡¡¡¡:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜