键盘弹出代码有效,但小键盘位于警告框后面 - Android

Keyboard Pop up Code works but the Keypad is behind the alert box - Android

下面是我的代码,我浏览了堆栈溢出并为我的弹出对话框编写了下面的代码,其中有 2 个 EditText,我需要在警报时弹出我的 SoftKeypad,当我触摸时它会弹出键盘edittext 但键盘在我的警报框后面。

所以我尝试在 alert.show() 下面强制弹出键盘,但它在后台弹出,警报出现在它上面。

请给出解决方案

代码:

for (int k = 0; k < mCompetitorMainList.getChildCount(); k++)
                    {
                        LinearLayout layout = (LinearLayout) mCompetitorMainList.getChildAt(k);
                        Button btn = (Button) layout.getChildAt(0);
                        String tag = (String) btn.getTag();
                        LinearLayout dataDetail = (LinearLayout) layout.getChildAt(2);

                        if (tag.equalsIgnoreCase("yes") && btn.getText().toString().equals("OTHERS"))
                        {

                            final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());

                            LayoutInflater inflater = getActivity().getLayoutInflater();
                            final View dialogView = inflater.inflate(R.layout.alert_other_competitor_item_detail, null);
                            ImageView addImg =(ImageView)dialogView.findViewById(R.id.addCompetitorImg);
                            ImageView removeImg = (ImageView)dialogView.findViewById(R.id.removeCompetitorImg);
                            final LinearLayout competitorOtherLayout = (LinearLayout)dialogView.findViewById(R.id.competitorLayout);

                            addImg.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {
                                    LayoutInflater inflaterLayout = getActivity().getLayoutInflater();
                                    View dialogViewLayout = inflaterLayout.inflate(R.layout.add_other_item_layout, null);
                                    EditText otherCompDesc = (EditText) dialogViewLayout.findViewById(R.id.otherCompetitorDescription);
                                    EditText otherCompQty = (EditText) dialogViewLayout.findViewById(R.id.otherCompetitorQty);

                                    otherCompDesc.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                                        @Override
                                        public void onFocusChange(View v, boolean hasFocus) {
                                            if (hasFocus) {
                                                InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                                                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                                            }
                                        }
                                    });

                                    otherCompQty.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                                        @Override
                                        public void onFocusChange(View v, boolean hasFocus) {
                                            if (hasFocus) {
                                                InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
                                                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
                                            }
                                        }
                                    });

                                    competitorOtherLayout.addView(dialogViewLayout);

                                }
                            });

                            removeImg.setOnClickListener(new View.OnClickListener() {
                                @Override
                                public void onClick(View v) {

                                    if(competitorOtherLayout.getChildCount()!=0)
                                    {
                                        competitorOtherLayout.removeViewAt(competitorOtherLayout.getChildCount()-1);
                                    }
                                    else
                                    {
                                        Toast.makeText(getActivity(),"No Other Competitor Present ",Toast.LENGTH_LONG).show();
                                    }

                                }
                            });

                            dialogBuilder.setView(dialogView);

                            alertDialogOther = dialogBuilder.create();
                            alertDialogOther.getWindow().setFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
                            alertDialogOther.show();

                            //alertDialogOther.setCancelable(false);


                            Toast.makeText(getActivity(), "Others Clicked", Toast.LENGTH_SHORT).show();
                            btn.setTag("no");
                        }
                        else if (tag.equalsIgnoreCase("yes"))
                        {
                            dataDetail.setVisibility(View.VISIBLE);
                            btn.setTag("no");
                        }
                        else
                        {
                            dataDetail.setVisibility(View.GONE);
                        }
                    }

屏幕截图:

private void openKeyboard(){
        InputMethodManager inputMethodManager =
                (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}

改用这个..