0

我有一个自定义键盘和两个EditTexts. 我在第一个编辑文本中输入数字,然后将焦点发送到第二个编辑文本并将其返回到第一个编辑文本。我的问题是我不能独立于第一个编辑文本写入第二个编辑文本。这是我的代码:

private class BtnListener implements OnClickListener {

    public void onClick(View view) {


        switch (view.getId()) {

        case R.id.btnNum0Id:
        case R.id.btnNum1Id:
        case R.id.btnNum2Id:
        case R.id.btnNum3Id:
        case R.id.btnNum4Id:
        case R.id.btnNum5Id:
        case R.id.btnNum6Id:
        case R.id.btnNum7Id:
        case R.id.btnNum8Id:
        case R.id.btnNum9Id:

            String inDigit = ((Button) view).getText().toString();

            if (inStr.equals("0")) {

                inStr = inDigit; 

              } else {
                inStr += inDigit;
              }

            editX.setText(inStr);

            editX.addTextChangedListener(new TextWatcher() {

                public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

                public void onTextChanged(CharSequence s, int start, int before, int count) {
                //Para Numero
                    if(editY.requestFocus() == true && editY.length() == 0 )
                    {
                        btnCalcula.setOnClickListener( new OnClickListener(){ 
                            public void onClick(View arg0){

                                int inNum = Integer.parseInt(inStr);

                                inStr = "0";

                                if (lastOperator == ' ') {
                                  result = inNum;//Asignacion de suma
                                  } else if (lastOperator == '+') {
                                      result += inNum; //Suma
                                      }

                                editZ.setText(String.valueOf(result).substring
                                        (0,editX.getText().length()-2));
                                mData.add(new Data(result));
                                mAdapter.notifyDataSetChanged();
                                lastOperator = '+';

                                    }   
                                });     
                    }

                }


                public void afterTextChanged(Editable s) {
                    //Para Pale
                    if(s.length() == 4 && editY.requestFocus() == true ){
                        btnCalcula.setOnClickListener( new OnClickListener() {
                            public void onClick(View v){
                                        if(editY.requestFocus() == true)
                                        {
                                            int inNum = Integer.parseInt(inStr);

                                            inStr = "0";

                                            if (lastOperator == ' ') {
                                              result = inNum;//Asignacion de suma
                                              } else if (lastOperator == '+') {
                                                  result += inNum; //Suma
                                                  }

                                            editZ.setText(String.valueOf(result).substring
                                                    (0,editY.getText().length()));
                                            mData.add(new Data(result));
                                            mAdapter.notifyDataSetChanged();
                                            lastOperator = '+';
                                            editY.clearFocus();
                                        }   
                                    }
                            });
                        //para Tripleta
                    }else if (s.length() == 6){
                        btnCalcula.setOnClickListener( new OnClickListener() {
                            public void onClick(View v){
                                //editY.requestFocus();
                                        if(editY.requestFocus() == true)
                                        {
                                            int inNum = Integer.parseInt(inStr);

                                            inStr = "0";

                                            if (lastOperator == ' ') {
                                              result = inNum;//Asignacion de suma
                                              } else if (lastOperator == '+') {
                                                  result += inNum; //Suma
                                                  }

                                            editZ.setText(String.valueOf(result).substring
                                                    (0,editY.getText().length()));
                                            mData.add(new Data(result));
                                            mAdapter.notifyDataSetChanged();
                                            lastOperator = '+';
                                            editY.clearFocus();
                                        }   
                                    }
                            });
                    }

                }

            });

                if (lastOperator == '=') {
                   result = 0;
                   lastOperator = ' ';
                }

              break;

           case R.id.btnClearId:
             result = 0;
             inStr = "0";
             lastOperator = ' ';
             editZ.setText("");
             editX.setText("");
             editY.setText("");
             mData.clear();
             mAdapter.notifyDataSetChanged();

              break;
           case R.id.btnAnula: 
               editX.setText("");
               editY.setText("");
               editY.clearFocus();
               break;
           case R.id.btnImprim:
               //Buscar Api
               break;
           case R.id.btnReimp:
               //Reimplementar api
               break;
           }
        }

}   
4

0 回答 0