Update the value obtained in an EditText

2

Next, I'm having a problem getting the value in an EditText and displaying it in a TextView. The value displayed when using a string, is "null", and when using int, it is 0. I believe this happens because the value being collected, is what appears before the typed, ie nothing!

I would like to know if there is any way to monitor the value entered in EditText so that when it is changed, the button will pick up the new value, not the previous one if that is the problem.

Thecodefortheclassresponsibleforthecalculationis here .

Edit: Just call the method within the Click event of the button.

btnCalc = (Button)findViewById(R.id.btnCalc);
                        btnCalc.setOnClickListener (new View.OnClickListener()
                    { 
                        public void onClick(View v)
                        {      
                                Calculate(); //este método
                                result = "#" + rst1 + remainderR + rst2 + remainderG + rst3 + remainderB;
                                txtResult.setText(result);     
                        }
                    });
    
asked by anonymous 08.05.2014 / 15:53

2 answers

4

Variables are NULL because they are only initialized in the Calculate() method, which is not being called when the button is clicked.

    
08.05.2014 / 16:08
1

I got this code on another forum, I think it might be useful for you:

final EditText edittext = (EditText) findViewById(R.id.edittext);
    edittext.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        // If the event is a key-down event on the "enter" button
        if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
            (keyCode == KeyEvent.KEYCODE_ENTER)) {
          // Perform action on key press
          Toast.makeText(HelloFormStuff.this, edittext.getText(), Toast.LENGTH_SHORT).show();
          return true;
        }
        return false;
    }
});

Basically it monitors an edit and when the user clicks enter it returns the information.

Follow the link for the credits: link

    
08.05.2014 / 16:08