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


Question

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?

1
18
10/30/2013 4:53:48 PM

Accepted Answer

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

17
2/2/2012 8:13:42 AM

The code should instead be something like this:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon