Android 可编辑文本到字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2216201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Editable text to string
提问by BIBEKRBARAL
How can I convert editable text into string in Android ? Any solution?
如何在 Android 中将可编辑文本转换为字符串?有什么解决办法吗?
回答by Alex Ntousias
回答by Jeremy Logan
Based on this code (which you provided in response to Alex's answer):
基于此代码(您为响应 Alex 的回答而提供的):
Editable newTxt=(Editable)userName1.getText();
String newString = newTxt.toString();
It looks like you're trying to get the text out of a TextViewor EditText. If that's the case then this should work:
看起来您正在尝试从TextView或EditText 中获取文本。如果是这种情况,那么这应该有效:
String newString = userName1.getText().toString();
回答by itechDroid
This code work correctly only when u put into button click because at that time user put values into editable text and then when user clicks button it fetch the data and convert into string
此代码仅在您单击按钮时才能正常工作,因为当时用户将值放入可编辑文本中,然后当用户单击按钮时,它会获取数据并转换为字符串
EditText dob=(EditText)findviewbyid(R.id.edit_id);
String str=dob.getText().toString();