安卓:是否有可能把用户输入和显示回来? [英] Android: Is it possible to take user input and display it back?

查看:277
本文介绍了安卓:是否有可能把用户输入和显示回来?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的这一点,但我试图把用户输入(即用户名),然后在不同的活动显示它通过一个TextView(即显示器将显示这是用户名的举动)。

I'm new to this but I'm trying to take user input (i.e. userName) and then display it in a different activity via a textView (i.e. display will show "it's 'userName's move").

我不知道我是否可以通过java文件分配用户输入一个字符串,然后用我的意图传递数据,或者如果我必须使用某种形式的存储的做到这一点。

I'm not sure if I can do this by assigning the user input to a string in the java file, then passing the data with my intent or if I have to use some form of storage.

无论哪种方式,我仍然困惑,我怎么能得到这个回字符串中的.xml文件显示。

either way, I'm still confused as to how I can get this back to a string in the .xml file to be displayed.

任何帮助将是非常美联社preciated :)
欢呼声

Any help would be much appreciated :) cheers

推荐答案

由于有人指出在评论中,你应该了解的意图是什么。你可以阅读他们这里。作为一个非常简单的例子:

As it was pointed in the comments, you should understand the what an Intent is. You can read about them here. As a very brief example:

Intent launchNewActivity = new Intent(this, NewActivity.class);
launchNewActivity.putExtra("Some key", "Some value"); //sometimes you want to pass extra data
startActivity(launchNewActivity);

此外,这将是很好太了解使用strings.xml中,因为的此处解释。基本上,它是用来定义常量不会硬codeD和您可以在code调用。它们可以帮助你保持你的code有组织,也有助于您的应用程序转换为轻松其他语言。再次,一个简单的例子如下所示:

Also, it would be good too to understand the use of strings.xml, as explained here. Basically, it is used to define constants that will not be hard-coded and you can call in your code. They help you to keep your code organized and also helps to translate your applications to other languages with ease. Again, a simple example is shown below:

<resources>

    <string name="OK">OK</string>
    <string name="cancel">Cancel</string>

    <!-- Validation error messages for EditText -->
    <string name="editText_validation_error_empty_field">The field cannot be empty.</string>
    <string name="editText_validation_error_numbers_only">Only numbers are allowed on this field.</string>
</resources>

这篇关于安卓:是否有可能把用户输入和显示回来?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆