Android - AlertDialog背后的键盘弹出窗口

时间:2015-07-25 16:30:57

标签: android listview keyboard android-edittext alertdialog

我有一个Android应用程序。我的应用程序有一个包含listview的alertDialog。

当我点击listview中的editText时,键盘会在alertdialog后面弹出,因此无法访问。

对此问题的任何帮助将不胜感激!提前谢谢!

enter image description here

我调用此函数来调用AlertDialog:

private void DProcedure(ApprovalOperationInput approvalOperationData, View convertView, ViewGroup parent)
    {
        LayoutInflater inflater = ((LayoutInflater) myContext.GetSystemService(Context.LayoutInflaterService));
        View rootView = inflater.Inflate(Resource.Layout.ApproveListview , null, false);


        ListView lst= ( ListView ) rootView.FindViewById(Resource.Id.list); 
        lst.ItemsCanFocus = true;
        List<ApprovalOperation> data = new List<ApprovalOperation> ();
        data = SetData ();
        approvalOperationAdapter = new ApprovalOperationAdapter (context, data.AsEnumerable ());
        lst.Adapter = approvalOperationAdapter;


        var builder = new AlertDialog.Builder(context);
        builder.SetIconAttribute(Android.Resource.Attribute.AlertDialogIcon);
        builder.SetTitle(Resource.String.list_dialog_title);
        builder.SetView (rootView);

        builder.SetPositiveButton(Resource.String.dialog_ok, OkClicked);
        builder.SetNegativeButton(Resource.String.dialog_cancel, CancelClicked);

        AlertDialog alertDialog = builder.Create ();

        alertDialog.Window.ClearFlags (WindowManagerFlags.NotFocusable);
        alertDialog.Window.ClearFlags (WindowManagerFlags.AltFocusableIm);  
        alertDialog.Window.SetSoftInputMode (SoftInput.StateVisible);


        alertDialog.ShowEvent  += delegate {
            InputMethodManager imm = (InputMethodManager) context.GetSystemService(Context.InputMethodService);
            imm.ToggleSoftInput (ShowFlags.Forced, 0);
        };


        alertDialog.Show (); 
        alertDialog.Window.SetSoftInputMode (SoftInput.StateVisible); 
    }

ApprovalOperationAdapter的GetView方法:

public override View GetView(int position, View convertView, ViewGroup parent)
    {  
        MyViewHolder holder = null;
        var view = convertView;
        if (view != null) 
            holder = view.Tag as MyViewHolder;
        if (holder == null) {
            holder = new MyViewHolder ();
            view = context.LayoutInflater.Inflate (Resource.Layout.ApproveRow, null);
            holder.text1 = view.FindViewById<TextView> (Resource.Id.example_row_iv_image);
            holder.text2 = view.FindViewById<TextView> (Resource.Id.example_row_tv_title);
            holder.text3 = view.FindViewById<TextView> (Resource.Id.tvdesc);
            holder.text4 = view.FindViewById<TextView> (Resource.Id.tvdesc1);
            holder.text5 = view.FindViewById<EditText> (Resource.Id.tvdesc2);

            holder.text5.Click += delegate {
                InputMethodManager imm = (InputMethodManager) context.GetSystemService(Context.InputMethodService);
                imm.ToggleSoftInput (ShowFlags.Forced, 0);
            }; 
            view.Tag = holder;
        } 

        holder.text1.Text = data [position].ApprovalOperationDescription;
        holder.text2.Text = data [position].ApprovalOperationLongCode;
        holder.text3.Text = data [position].ApprovalOperationControlledEve;
        holder.text4.Text = data [position].ApprovalOperationApprovalNumer;  
        return view; 
    }

1 个答案:

答案 0 :(得分:1)

我解决了我的问题: 我在创建的地方添加了这段代码并显示了对话框:

        AlertDialog alertDialog = builder.Create ();

        InputMethodManager imm = (InputMethodManager) context.GetSystemService(Context.InputMethodService);
        imm.ToggleSoftInput (ShowFlags.Forced, 0); 

        alertDialog.Show (); 

        alertDialog.Window.ClearFlags(WindowManagerFlags.NotFocusable);
        alertDialog.Window.ClearFlags(WindowManagerFlags.AltFocusableIm);
        alertDialog.Window.SetSoftInputMode (SoftInput.StateVisible);