0

So I try to show the String variable in GUI that I inherit from a parent activity.

This is my xml code

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="5dp"
    android:inputType="text"
    android:textStyle="italic"
    android:id="@+id/Edit_Title_Update"
    android:text="@string/updating_title"/>

This is my String definition

 <string name="updating_title"> %s </string>

This is how I try to put date into the String

    String updating_title = getString(R.string.updating_title, show_title);
    Log.e("MyTag","Here2 "+updating_title);

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_update__diary);

In the console I can see the variable is correct

01-05 10:19:29.767    2849-2849/com.example.wenhaowu.diaryproject E/MyTag﹕ Here2 Happy

But In the emulator the String remains the same

enter image description here

What is the problem and how can I fix it? Thank you.

2 Answers 2

2

Changing String updating_title won't change the actual String resource updating_title in strings.xml.

You would need to set text in EditText in your activity after setContentView

Like:

EditText e = (EditText) findViewById (R.id.my_edt_text);
e.setText(updating_title);

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

1

nothing is wrong, you just need to find your EditText and call setText on the instance, to update its content with the new value. After setContetView

EditText t = (EditText)  findViewById(R.id.Edit_Title_Update);
t.setText(updating_title);

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.