Android EditText OnClickListener问题

Pir*_*aba 3 android

我有销售申请.当用户单击EditText时,弹出计算器想要显示.在我的情况下,当用户双击EditText onClickLister它时,它会显示弹出计算器.

这是myEditText

    final EditText txtQty = new EditText(this);
            txtQty.setHeight(1);
            if(productList.get(i).getQty() != 0.00){
                txtQty.setText(Double.toString(productList.get(i).getQty()));
            }
            txtQty.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,42));
            txtQty.setTextSize(9);
            txtQty.setId(i);
            txtQty.setHint("0");
            txtQty.setClickable(true);
            txtQty.setSelected(true);
            txtQty.setSelectAllOnFocus(true);
            txtQty.setInputType(InputType.TYPE_NULL);
            tr.addView(txtQty); 
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

   txtQty.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
                    String productCode= txtCode.getText().toString();
                    double price = getProductPrice(productCode).getPrice();
                    txtPrice.setText(""+price);

                    if(invPriceEdit.equals("3")){ 
                        if(editPrice.getText().toString().equals("") || editPrice.getText().toString().equals("0.00") || editPrice.getText().toString().equals("0") || editPrice.getText().toString().equals("0.0")){
                            txtPrice.setText(""+ price);
                            editPrice.setText("" +price);
                        }else{
                            String ePrice = editPrice.getText().toString();
                            editPrice.setText("" +ePrice);
                        }
                    }


                        keyAmount = new StringBuffer();
                        if(keyAmount.length() > 0){
                            keyAmount.delete(0, keyAmount.length());
                        }

                        int[] origin = new int[2];
                        v.getLocationOnScreen(origin);
                        final int xVal = origin[0];
                        final int yVal = origin[1] ;

                        dialog = new Dialog(SalesActivityGroup.group.getParent());
                        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

                        View vLoad = LayoutInflater.from(SalesActivityGroup.group.getParent()).inflate(R.layout.key_pad, null);
                        dialog.setContentView(vLoad);
                        android.view.WindowManager.LayoutParams lp= dialog.getWindow().getAttributes();  

                        dialog.setCancelable(true);
                        dialog.setCanceledOnTouchOutside(true);  
                        lp.x = xVal;
                        lp.y = yVal;
                        lp.width = LayoutParams.WRAP_CONTENT;
                        lp.height = LayoutParams.WRAP_CONTENT;
                        lp.gravity = Gravity.TOP | Gravity.LEFT;
                        lp.dimAmount = 0;            
                        dialog.getWindow().setAttributes(lp);
                        dialog.setCancelable(false);
                        keyamDisplay  = (TextView)dialog.findViewById(R.id.keyamDisplay);

                        Button  txtone = (Button)dialog.findViewById(R.id.txtone);
                        txtone.setOnClickListener(new OnClickListener() {
                           public void onClick(View v) {
                              keyAmount.append("1");
                              keyamDisplay.setText("" + keyAmount.toString());

                           }
                        });

                        Button  txttwo = (Button)dialog.findViewById(R.id.txttwo);
                        txttwo.setOnClickListener(new OnClickListener() {
                           public void onClick(View v) {
                              keyAmount.append("2");
                              keyamDisplay.setText("" + keyAmount.toString());

                           }
                        });

                        Button  txtthree = (Button)dialog.findViewById(R.id.txtthree);
                        txtthree.setOnClickListener(new OnClickListener() {
                           public void onClick(View v) {
                              keyAmount.append("3");
                              keyamDisplay.setText("" + keyAmount.toString());
                           }
                        });

                        Button  txtfour = (Button)dialog.findViewById(R.id.txtfour);
                        txtfour.setOnClickListener(new OnClickListener() {
                           public void onClick(View v) {
                              keyAmount.append("4");
                              keyamDisplay.setText("" + keyAmount.toString());
                           }
                        });

                        Button  txtfive = (Button)dialog.findViewById(R.id.txtfive);
                        txtfive.setOnClickListener(new OnClickListener() {
                           public void onClick(View v) {
                              keyAmount.append("5");
                              keyamDisplay.setText("" + keyAmount.toString());
                           }
                        });

                        Button  txtsix = (Button)dialog.findViewById(R.id.txtsix);
                        txtsix.setOnClickListener(new OnClickListener() {
                           public void onClick(View v) {
                              keyAmount.append("6");
                              keyamDisplay.setText("" + keyAmount.toString());
                           }
                         });

                        Button  txtseven = (Button)dialog.findViewById(R.id.txtseven);
                        txtseven.setOnClickListener(new OnClickListener() {
                           public void onClick(View v) {
                              keyAmount.append("7");
                              keyamDisplay.setText("" + keyAmount.toString());
                           }
                        });

                        Button  txteight = (Button)dialog.findViewById(R.id.txteight);
                        txteight.setOnClickListener(new OnClickListener() {
                           public void onClick(View v) {
                              keyAmount.append("8");
                              keyamDisplay.setText("" + keyAmount.toString());
                           }
                        });

                        Button  txtnine = (Button)dialog.findViewById(R.id.txtnine);
                        txtnine.setOnClickListener(new OnClickListener() {
                           public void onClick(View v) {
                              keyAmount.append("9");
                              keyamDisplay.setText("" + keyAmount.toString());
                           }
                        });

                        Button  txtZero = (Button)dialog.findViewById(R.id.txtZero);
                        txtZero.setOnClickListener(new OnClickListener() {
                           public void onClick(View v) {
                              keyAmount.append("0");
                              keyamDisplay.setText("" + keyAmount.toString());
                           }
                        });

                        Button  txtdot = (Button)dialog.findViewById(R.id.txtdot);
                        txtdot.setEnabled(false);
                        txtdot.setOnClickListener(new OnClickListener() {
                               public void onClick(View v) {
                                  keyAmount.append(".");
                                  keyamDisplay.setText("" + keyAmount.toString());
                               }
                        });

                        Button  diaDelete = (Button)dialog.findViewById(R.id.diaDelete);
                        diaDelete.setOnClickListener(new OnClickListener() {
                           public void onClick(View v) {
                             if(keyAmount.length() > 0){
                                keyAmount.delete(keyAmount.length()-1, keyAmount.length());
                            }
                                keyamDisplay.setText("" + keyAmount.toString());
                           }
                        });

                        ImageButton imageSmileExit = (ImageButton)dialog.findViewById(R.id.imageSmileExit);
                        imageSmileExit.setOnClickListener(new OnClickListener() {
                            public void onClick(View v) {
                                dialog.dismiss();
                            }
                        });

                        Button  txtDialogOK = (Button)dialog.findViewById(R.id.txtDialogOK);
                        txtDialogOK.setOnClickListener(new OnClickListener() {
                           public void onClick(View v) {
                               dialog.dismiss();
                         }

                      });
                    dialog.show();
                    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
                }
                }
Run Code Online (Sandbox Code Playgroud)

这是销售代表的一个问题.他们希望双击每一个产品clcik.

我想在用户选择textEditor时显示弹出计算器.(不要双击).

这是我的代码:

       final EditText txtQty = new EditText(this);
            txtQty.setHeight(1);
            if(productList.get(i).getQty() != 0.00){
                txtQty.setText(Double.toString(productList.get(i).getQty()));
            }
            txtQty.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,42));
            txtQty.setTextSize(9);
            txtQty.setId(i);
            txtQty.setHint("0");
            txtQty.setInputType(InputType.TYPE_NULL);
            tr.addView(txtQty); 
Run Code Online (Sandbox Code Playgroud)

问题是:

`TableLayout包含产品信息列表,当用户点击Qty后弹出计算器输入值后,它将清除那一行上的EditText数量&它转到第一行EditText'

这是我的屏幕图片

我的屏幕的图片

May*_*ank 6

为什么要添加onClickEventEditText,

对于EditText,onFocusChangeListener()只要edittext获得焦点,就可以使用它来激活对话框.在onFocusChangeListener()你可以检查是否EditText正在获得焦点或失去焦点.


Pir*_*aba 5

我已经使用了setOnTouchListener

    disValEdit.setOnTouchListener(new OnTouchListener() {
                public boolean onTouch(View v, MotionEvent event) {
                    if(event.getAction() == MotionEvent.ACTION_UP) { } });
Run Code Online (Sandbox Code Playgroud)