android - 如何在android中获取用户的输入

标签 android

我在 android 中有一个 EditText,我希望用户在其中输入文本并检查条件“BYE”

代码示例:

EditText text = (EditText)findViewById(R.id.EditText01);
String abc= text .getText().toString(); 

while( !(abc).equals("bye")){

   abc = text.getText().toString();//user should enter the text from keyboard and the while loop should go and chech the condition.but not able to enter the text

   //do some operation with abc

 }

如何让用户输入文本?UI 应该等待输入文本(类似于我们在 Java 应用程序中有 InputStreamReader)。

最佳答案

非常简单:-

EditText text = (EditText)findViewById(R.id.EditText01); 
String str = text.getText().toString(); 

现在在 str 中你将得到在 EditText 中输入的字符串

关于android - 如何在android中获取用户的输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3766900/

相关文章:

android - Android 2.X 设备可以连接到 Android 4.0 Wifi Direct AP 吗?

java - Android 数据绑定(bind) : ConcurrentModificationException while using ternary operator in method parameter

android - LifeCycleAware Fragment 中的 fragment 生命周期事件

android - Flutter 默认启动 View 淡入淡出动画

java - 如何在android中提取IP地址的前三段

android - 在 Android ConstraintLayout 中创建具有可变数量 n 的网格 (n × n)

android - 如果不创建线程,是否需要获取WakeLock?

java - OpenCV Android imwrite 给我一个蓝色图像

android - 无法从 Google Play 购买应用内产品

android - 如何停止 logcat 消息