如何采取从用户的android输入 [英] how to take input from user in android

查看:132
本文介绍了如何采取从用户的android输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的EditText android系统中,我希望用户输入条件的文本,并检查BYE

i have a EditText in android in which i want the user to enter the text and checks for the condition "BYE"

code样品:<​​/ P>

Code sample:

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

 }

我怎样才能让用户输入文字??用户界面应该等待文本输入(类似我们的InputStreamReader在Java应用程序)。

How can i make user to enter the text??The UI should wait for the text to be entered(something like we have InputStreamReader in java applications).

推荐答案

我不认为你需要一个循环做到这一点。从您的评论看起来你也有一个Enter键或单击做检查的东西。只需设置一个onclicklistener和的onclick可以使无形的EditText(或不编辑),检查是的EditText等于BYE,然后你的行动可能会是这个样子:

I don't think you need a loop to do this. From your comment it looks like you also have an "Enter" button or something that you click to do the checking. Just set an onclicklistener and onclick you can make the edittext invisible (or un-editable), check is the edittext is equal to "BYE" and then do your actions might look something like this:

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输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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