2015-01-05 22 views
0

所以我尝试在GUI中显示我从父活动继承的字符串变量。在xml文件中使用字符串变量(android studio)

这是我的XML代码

<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"/> 

这就是我的列定义

<string name="updating_title"> %s </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); 

在控制台我可以看到变量是否正确

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

但在模拟器字符串保持不变

enter image description here

这是什么问题,我该如何解决?谢谢。

回答

2

更改String updating_title后在的strings.xml不会改变实际字符串资源updating_title

您需要后setContentView

就像在你的活动设置文本的EditText:

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

希望这有助于。

+0

艾谢谢你。得到它了。有用 – WenhaoWu

1

什么是错的,你只需要找到自己的EditText,并呼吁setText上的实例,以更新其与新价值的内容。 setContetView

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

谢谢你现在的作品 – WenhaoWu