成功登录后将值附加到TextView

时间:2012-04-13 20:40:48

标签: android android-intent

我的应用中有一个登录表单。我想在用户成功登录后显示“欢迎”消息。我将userid作为值传递给intent,同时从登录屏幕移动到主屏幕,如下所示:

Intent intent = new Intent(this,ApplicationHomeActivity.class);
intent.putExtra("UserId", txtUserId.getText().toString());
startActivity(intent);

然后在主屏幕中,我在layout.xml文件中将TextView值设置为“Welcome”,因为“Welcome”部分是所有用户的一个字符串。然后我使用以下代码获取用户名:

Bundle bundle = getIntent().getExtras();
String userId = bundle.getString("UserId");

现在我想将userId附加到TextView(在layout.xml中包含“Welcome”)并将其显示给用户。我无法找到任何append()方法,因此我无法将userId附加到“欢迎”。那怎么办?需要一些帮助。

此致

3 个答案:

答案 0 :(得分:1)

您需要自己添加:

txtUserId.setText(txtUserId.getText().toString() + appendedText);

答案 1 :(得分:0)

只需执行"Welcome" + userID这会将用户ID附加到欢迎文字

答案 2 :(得分:0)

您可以在资源中将欢迎字符串定义为Welcome $1%s,然后

txtUserId.setText(getString(R.string.welcome, bundle.getString("UserId"));

请参阅http://developer.android.com/reference/android/content/Context.html#getString%28int,%20java.lang.Object...%29