2016-10-03 61 views
0

在下面的代碼,我嘗試值alertdialog通過的EditText添加到表時,存錢按鈕clicked.Now當我點擊存錢按鈕,2 EditText上出現,但是當我專注於任何他們的softkeypad是不會彈出up.I嘗試了所有的解決方案,但沒有奏效Softkeypad亙古不變的彈出

    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); 

         } 

回答

0

你把「< requestFocus的/>」爲EditTexts在XML?

+0

I M添加的EditText編程 –

+0

edittext.requestFocus(); – DroidDev

+0

它變得焦點,但鍵盤不彈出 –

相關問題