我如何传递参考值(基本)?
在我的 FormActivity
中,有两个 EditText
:
EditText editname = (EditText) findViewById(R.id.idname);
EditText editage = (EditText) findViewById(R.id.idage);
然后当用户点击时:
String name = editname.getText().toString();
int age = parseInt(editage.getText().toString());
现在我的目的是......
下次我访问页面(FormActivity)时,最后一个值编辑名称和编辑年龄仍然存在,
谢谢:)
In my FormActivity
, there are two EditText
's:
EditText editname = (EditText) findViewById(R.id.idname);
EditText editage = (EditText) findViewById(R.id.idage);
then when user clicks:
String name = editname.getText().toString();
int age = parseInt(editage.getText().toString());
now my purpose is...
next time i visit the page(FormActivity), the last value of the editname and edit age is still there
thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否想预先填充这些字段?如果是这样,您可以将它们存储在 Activity 的 Bundle 中,然后在 onResume() 方法中恢复它们。您还可以将它们存储在设备的闪存上,因为您的应用程序分配了一些内存用于存储配置,并且您可以在应用程序启动时从本地存储中读回它们
Are you trying to prepopulate those fields? If so, you can store them in the Bundle for your Activity and then restore them in the onResume() method. You can also store them on your device's flash memory, since your application is allocated some memory for storing configuration, and you could read them back out of local storage when your application starts
TextView nameField = (TextView) this.findViewById(R.id.name);
假设您已经使用 setContentView(R.layout.editinfo); 加载了布局。
TextView nameField = (TextView) this.findViewById(R.id.name);
This is assuming that you already loaded the layout using setContentView(R.layout.editinfo);
使用
TextView.setText(Activity.getString(R.id.name));
(而Activity
是您的主要活动)编辑:可能误解了问题。如果您想要的字符串位于 xml 中,请使用此选项。如果您想引用 xml 中的 TextView,请使用
findViewById
。Use
TextView.setText(Activity.getString(R.id.name));
(whileActivity
is your main activity)edit: probably misundersood the question. use this if the string you want is in the xml. if you want to reference a TextView that is in the xml, use
findViewById
.