views:

144

answers:

1

Hi,

I am exploring android and developement and I found one problem.

My app UI is defined in main.xml

I have 2 texts and 2 buttons defined - easy app.

I read that I may be able to change TEXT in the ACTIVITY using the setText() method.

And thats the problem - how do I POINT the setText() Method? How do I tell it to change a specified text?

If I would declare the TextView inside the Activity with NEW TextView NAME Object, I would just need to use NAME.setText(STRING)... But I didnt so i dont have anything like NAME of the object?

How can this be done? I read something about r.IDs but I truly dont have a idea how to use them, where to find them and how to implement it ....

Please advise

Thank you

Oliver

+2  A: 

You don't need do define a new TextView. You need this code:

TextView textView = (TextView) findViewById(R.id.name_of_your_textview);
textView.setText("bla bla bla");
Roflcoptr
yes but what is R.id.name_of_your_textview ??where do I specify the view name?you know my XML looks like :<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/how_to" android:layout_marginBottom="30dip" android:textSize="12sp" />I dont see any ID or name there :((
Oliver Goossens
then add a line in your XML:android:id="@+id/name_of_yout_textview"
Roflcoptr
ahaaaa !!!! k ill test thank you
Oliver Goossens