Android:EditText的getText方法出现问题
在我的项目中,我有两个活动或课程。在第一个活动中,我有一个 EditText,我想从第二堂课获取它的文本。
在第一堂课中,我编写了这段代码,但似乎有问题。
public String getTextMessage()
{
return textMessage.getText().toString();
}
因为在第二节课时,当我想要得到它时,程序崩溃了。
message = encode.getTextMessage();
你的建议是什么?
In my project I have two activities or classes. In first activity I have a EditText and I want to get the text of it from second class.
In the first class I wrote this code but it seems has problem.
public String getTextMessage()
{
return textMessage.getText().toString();
}
because in second class when I want to get it, program crashes.
message = encode.getTextMessage();
What is your suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正如 sunil 所说,您必须首先从 edittextbox 获取字符串,然后通过意图将其发送到另一个第二个活动。第二个活动开始后,您必须从捆绑中获取文本。
代码片段如下...
活动 A
活动 B
As told by sunil you have to firstly get string from edittextbox and through intent send it to another second activity. After start of second activity you have to get text from bundle.
code snippet is given below...
Activity A
Activity B
通过 getText() 从编辑文本中访问文本并将其存储在字符串中。当您移动到第二个活动时,通过bundel将字符串变量发送到第二个类。在第二类中提取bundel并使用它。
Access the text by getText() from edit text and store it in an string. when you move to second activity sent string variable to second class via bundel. Extract the bundel in second class and use it.
您必须通过意图传递值
You have to pass the value through intents