【问题标题】:Android - Keyboard pop ups behind AlertDialogAndroid - AlertDialog 后面弹出键盘
【发布时间】:2015-10-16 04:44:36
【问题描述】:

我有一个安卓应用程序。我的应用程序有一个包含列表视图的 alertDialog。

当我单击位于列表视图中的 editText 时,键盘会在 alertdialog 后面弹出,因此无法访问。

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

我调用这个函数来调用 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; 
    }

【问题讨论】:

    标签: android listview keyboard android-edittext android-alertdialog


    【解决方案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);
    

    【讨论】:

      猜你喜欢
      • 2017-01-09
      • 1970-01-01
      • 2015-06-06
      • 2014-12-01
      • 1970-01-01
      • 2015-01-26
      • 2021-01-19
      • 1970-01-01
      • 2011-01-30
      相关资源
      最近更新 更多