如何从android中的用户获取输入

如何从android中的用户获取输入,第1张

概述我在 android中有一个EditText,我希望用户输入文本并检查条件“BYE” 代码示例: EditText text = (EditText)findViewById(R.id.EditText01);String abc= text .getText().toString(); while( !(abc).equals("bye")){ abc = text.getText 我在 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).

解决方法 我认为你不需要循环来做到这一点.从您的评论中看起来您还有一个“输入”按钮或您点击进行检查的内容.只需设置一个onclickListener并onclick你可以使edittext不可见(或不可编辑),检查edittext是否等于“BYE”然后你的行为可能看起来像这样:
final EditText ET = (EditText) findVIEwByID(R.ID.EnterText);button B1 = (button) findVIEwByID(R.ID.Enterbutton);B1.setonClickListener(new VIEw.OnClickListener() {                public voID onClick(VIEw v) {                    ET.setVisibility(VIEw.INVISIBLE);                    if(ET.getText().toString() == "BYE")                    {                        //do something if it is "BYE"                    } else {                        Context context = getApplicationContext();                    CharSequence text = "Please enter BYE";                    int duration = Toast.LENGTH_SHORT;                    Toast toast = Toast.makeText(context,text,duration);                    toast.show();                     }                    ET.setVisibility(VIEw.VISIBLE);                } });
总结

以上是内存溢出为你收集整理的如何从android中的用户获取输入全部内容,希望文章能够帮你解决如何从android中的用户获取输入所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1134839.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存