我的应用中有一个登录表单。我想在用户成功登录后显示“欢迎”消息。我将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附加到“欢迎”。那怎么办?需要一些帮助。
此致
答案 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"));