Why can't I set text to an Android TextView?

143,698

Solution 1

In your java class, set the "EditText" Type to "TextView". Because you have declared a TextView in the layout.xml file

Solution 2

The code should instead be something like this:

TextView text = (TextView) findViewById(R.id.this_is_the_id_of_textview);
text.setText("test");

Solution 3

Try Like this :

TextView text=(TextView)findViewById(R.id.textviewID);
text.setText("Text");

Instead of this:

text = (EditText) findViewById(R.id.this_is_the_id_of_textview);
text.setText("TEST");

Solution 4

To settext in any of in activity than use this below code... Follow these step one by one:

1.Declare

    private TextView event_post;

2.Bind this

    event_post = (TextView) findViewById(R.id.text_post);

3.SetText in

    event_post.setText(event_post_count);

Solution 5

Or you can do this way :

((TextView)findViewById(R.id.this_is_the_id_of_textview)).setText("Test");
Share:
143,698
Christoph
Author by

Christoph

Interested in Web Technologies

Updated on July 09, 2022

Comments

  • Christoph
    Christoph almost 2 years

    I'm having a problem with setting text to a TextView:

    TextView android:editable = "true".
    

    In my .java it seems like that this should work:

     text = (EditText) findViewById(R.id.this_is_the_id_of_textview);
    text.setText("TEST");
    

    But it doesn't. Can anyone tell me what's wrong here?