为什么我们在使用EditText之后使用String message = editText.getText().toString()? [英] Why we use String message = editText.getText().toString() after using EditText editText = (EditText) findViewById(R.id.edit_message);

查看:238
本文介绍了为什么我们在使用EditText之后使用String message = editText.getText().toString()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是android开发的新手.我正在学习android开发,因为这里是一段代码

I am new to android development. I am learning android development given here their is a piece of code

Intent intent = new Intent(this, DisplayMessageActivity.class);
EditText editText = (EditText) findViewById(R.id.edit_message);
String message = editText.getText().toString();
intent.putExtra(EXTRA_MESSAGE, message);

我想知道为什么我们在使用EditText之后再使用String message = editText.getText().toString().editText =(EditText)findViewById(R.id.edit_message); EditText返回什么?

I want to know why we use String message = editText.getText().toString() after using EditText editText = (EditText) findViewById(R.id.edit_message); What does EditText return?

推荐答案

使用EditText editText =(EditText)findViewById(R.id.edit_message);

此行将您的xml editText注册到类文件editText.在开发应用程序时,设计是在xml文件中完成的,编码是在.class文件中的.

This line registers your xml editText with the class file editText. As you develop an app, the design is done in the xml file and coding is in the .class file.

它在某些地方充当侦听器,例如,如果您在editText中编写了一些内容,

Somewhere it is working as a Listener, like if you write something in the editText then,

Using EditText editText = (EditText) findViewById(R.id.edit_message); 

通过此行,通知editText被通知.

By this line it is notified that the editText is notified.

注意:如果您直接执行String message = editText.getText().toString().不执行此操作
EditText editText = (EditText) findViewById(R.id.edit_message)您将获得NullPointer异常.

NOTE: If you do directly String message = editText.getText().toString().without doing this
EditText editText = (EditText) findViewById(R.id.edit_message) you will get NullPointer Exception.

这篇关于为什么我们在使用EditText之后使用String message = editText.getText().toString()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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