Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 920
Christoph Avatar asked Jul 18 '10 12:07

Christoph


People also ask

Which method is used to set the text in a TextView?

Set The Text of The TextView You can set the text to be displayed in the TextView either when declaring it in your layout file, or by using its setText() method.

Can we change the text in TextView?

TextView tv1 = (TextView)findViewById(R. id. textView1); tv1. setText("Hello"); setContentView(tv1);

How do I get TextView text?

String a = tv. getText(). toString(); int A = Integer. parseInt(a);

What is the use of setText in android?

SetText(String, TextView+BufferType)Sets the text to be displayed using a string resource identifier.


4 Answers

The code should instead be something like this:

TextView text = (TextView) findViewById(R.id.this_is_the_id_of_textview);
text.setText("test");
like image 165
ControlAltDelete Avatar answered Oct 16 '22 06:10

ControlAltDelete


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

like image 28
Noman Avatar answered Oct 16 '22 07:10

Noman


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);
like image 5
patel135 Avatar answered Oct 16 '22 08:10

patel135


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");
like image 5
Bunny Avatar answered Oct 16 '22 06:10

Bunny