Softkeypad不会在Custom AlertDialogBox中弹出

时间:2016-10-03 20:36:19

标签: android android-edittext android-alertdialog

在下面的代码中,当点击存款点按钮时,我试图通过edittext在alertdialog中为表添加值。现在当我点击存钱按钮时,出现2 edittext但当我专注于其中任何一个时,softkeypad不会弹出up.I尝试了所有解决方案,但没有任何效果

                    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);

                    LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    View view1 = inflater.inflate(R.layout.record_in_new, null);
                    alertDialogBuilder.setView(view1);

                    TextView cust_txt=(TextView)view1.findViewById(R.id.title);
                    cust_txt.setText((R.string.record));
                    final AlertDialog alertDialog = alertDialogBuilder.create();

                    final View view2=view1;

                    alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
                    alertDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
                    alertDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
                    alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
                    alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                    alertDialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

                    alertDialog.show();

                   alertDialog.findViewById(R.id.deposit_money).setOnClickListener(new View.OnClickListener()
                    {
                        EditText myEditDate = new EditText(view2.getContext());
                        EditText myEditAmount = new EditText(view2.getContext());

                        @Override

                        public void onClick(View v) {

                         LinearLayout.LayoutParams param = new TableRow.LayoutParams(
                                    TableRow.LayoutParams.MATCH_PARENT,
                                    TableRow.LayoutParams.MATCH_PARENT, 1.0f);

                            LinearLayout mLinear = (LinearLayout) view2.findViewById(R.id.editlayout);
                            LinearLayout mtxt = (LinearLayout) view2.findViewById(R.id.textbar);
                            LinearLayout medit = (LinearLayout) view2.findViewById(R.id.editboxes);
                            LinearLayout ldate = (LinearLayout) view2.findViewById(R.id.date);
                            LinearLayout lamount = (LinearLayout) view2.findViewById(R.id.amount);
                            LinearLayout lbutton = (LinearLayout) view2.findViewById(R.id.buttonlayout);
                            LinearLayout mbt1 = (LinearLayout) view2.findViewById(R.id.bt1);
                            LinearLayout mbt2 = (LinearLayout) view2.findViewById(R.id.bt2);
                            LinearLayout.LayoutParams mRparams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT);



                            medit.setWeightSum(2);

                            TextView title = new TextView(view2.getContext());
                            title.setText("Enter Deposit Date and Amount");
                            mtxt.addView(title);
                            TextView date = new TextView(view2.getContext());
                            date.setText("Date");
                            ldate.setLayoutParams(param);
                            ldate.setGravity(View.TEXT_ALIGNMENT_CENTER);
                            ldate.addView(date);
                            ldate.addView(myEditDate);

                            TextView amount = new TextView(view2.getContext());
                            amount.setText("Amount");
                            lamount.setLayoutParams(param);
                            lamount.setGravity(View.TEXT_ALIGNMENT_CENTER);
                            lamount.addView(amount);
                            myEditDate.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                                @Override
                                public void onFocusChange(View v, boolean hasFocus) {
                                    if (hasFocus) {
                                        alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
                                    }
                                }
                            });
                            myEditDate.setOnKeyListener(new View.OnKeyListener() {
                                @Override
                                public boolean onKey(View v, int keyCode, KeyEvent event) {
                                    String tmp = myEditDate.getText().toString();
                                    if (keyCode == KeyEvent.KEYCODE_DEL) {

                                        myEditDate.setText("");


                                    }
                                    return false;
                                }
                            });
                            lamount.addView(myEditAmount);

                        }

1 个答案:

答案 0 :(得分:0)

您是否在Xml中为EditTexts添加了“< requestFocus /> ”?