0

I recently started to use the ADT (also I don't know java yet, I'm familiar with C++).

I added a TextView which has a string as its text:

 <TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/button1"
    android:layout_marginBottom="35dp"
    android:layout_toRightOf="@+id/textView1" 
    android:text="@string/button_clicked" />

<string name="button_clicked">0</string>

(In the file activity_main.xml for layout and string.xml for the string)

Now my problem is to change the text in that TextView. But I don't want to change it directly, I want to change the string. (this happens due to a onClick event of a button)

Up to now I didn't work out how to do that and as well, how to cast the value of an int into that string somehow (I want it to count up / display the value of this integer).

Can you guys help me out? :)

2
  • Use the setText method and String.valueOf? Commented Feb 11, 2014 at 12:28
  • tv.setText(getText(R.string.button_clicked)); some thing like this our u want diffrent Commented Feb 11, 2014 at 12:30

1 Answer 1

2

If you just want to set a String as text:

myTextView.setText(myString);

For integers, use:

myTextView.setText(Integer.toString(integer));

For string resources, use:

myTextView.setText(R.string.my_string_res);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.