-1

I have a problem whith the result of this code.

private void listenbtnOK(){
        btnValider.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String cip1  =" hello ";
                String cip =findViewById(R.id.txtCip).toString();
 
                Log.d("couche presentation","*****************ok "+cip1);
                Log.d("couche presentation","*****************ok "+cip);
 
            }
        });
    }

Of course in the EditText txtCip I wrote "hello". In logCat I have :

  1. 06-22 13:58:12.559 ......D/couche*presentation: *****************ok hello
  2. 06-22 13:58:12.569 ..... D/couche*presentation: *****************ok androidx.appcompat.widget.AppCompatEditText{41b34980 VFED..CL ........ 0,34-204,83 #7f0700bd app:id/txtCip}

I would like to catch "hello" in cip string.

  • 1
    Does this answer your question? [How to get EditText value and display it on screen through TextView?](https://stackoverflow.com/questions/4396376/how-to-get-edittext-value-and-display-it-on-screen-through-textview) – Alexander Hoffmann Jun 25 '20 at 11:41
  • if you need get the text of the edit text you can do like this
    it is getting the object of the edit text and cast it into AppCompatEditText then you can get the text String cip = ((AppCompatEditText) findViewById(R.id.txtCip)).getText().toString();
    – sourabh karmakar Jun 25 '20 at 11:46

1 Answers1

0

Change String cip =findViewById(R.id.txtCip).toString(); to :

 String cip =findViewById(R.id.txtCip).getText().toString();
Alpha 1
  • 4,118
  • 2
  • 17
  • 23
  • Thanks, getText() couldn't be resolve so I split the code. I declare an EditText first ''' txtCip = (EditText)findViewById(R.id.txtCip); String cip =txtCip.getText().toString(); ''' and it works. thank you – Ahmed Bamba Jun 25 '20 at 12:07