
代码示例:
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中的用户获取输入所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)