Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 关闭对话框后,键盘不会显示_Android_Dialog - Fatal编程技术网

Android 关闭对话框后,键盘不会显示

Android 关闭对话框后,键盘不会显示,android,dialog,Android,Dialog,你好,我有一个活动,我从中调用一个对话框。当对话框出现时,我在编辑文本中写入一些内容,然后单击保存按钮。。。问题是,在关闭对话框并返回活动后,键盘仍保留在那里 我已经尝试过这样做: a) 在布局(xml)中: b) 在布局(xml)中: c) 在舱单中: android:windowSoftInputMode="stateHidden" 但这不起作用…键盘在关闭对话框后不显示 能给我一些线索来解决我的问题吗 我的对话框代码: public class DialogCreamodListas e

你好,我有一个活动,我从中调用一个对话框。当对话框出现时,我在编辑文本中写入一些内容,然后单击保存按钮。。。问题是,在关闭对话框并返回活动后,键盘仍保留在那里

我已经尝试过这样做:

a) 在布局(xml)中:

b) 在布局(xml)中:

c) 在舱单中:

android:windowSoftInputMode="stateHidden"
但这不起作用…键盘在关闭对话框后不显示

能给我一些线索来解决我的问题吗

我的对话框代码:

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.DIFERENCIA};
                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);  
                }
        }


}

要手动关闭软键盘,可以执行以下操作:

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

其中,
editText
是软键盘当前正在与之交互的editText。

要使dissapear成为键盘,必须删除清单中调用对话框的活动中的以下参数

android:windowSoftInputMode...
我有一个应该隐藏键盘的东西

android:windowSoftInputMode="stateHidden"

但是当我删除整行代码后,它就可以工作了:

您的对话框代码在哪里?我想你可能是在凌驾于你自己之上!我已经用代码编辑了帖子;)当我将代码放在我的.java中时,我得到一个错误编译getSystemService没有定义到我的对话框中。我将此工作用于活动,但如何在对话框中使工作getSystemService?好的,最后这是编译但不工作的代码:((
InputMethodManager imm=(InputMethodManager)mContext.getSystemService(Context.INPUT\u方法\u服务);imm.HideOffInputFromWindow(etxlistarepp.getWindowToken(),0);
android:windowSoftInputMode...
android:windowSoftInputMode="stateHidden"