如何检测重点的EditText android系统中? [英] How can I detect focused EditText in android?

查看:103
本文介绍了如何检测重点的EditText android系统中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司拥有一批的EditText 的在我的页面以及两个按钮。我希望用户触摸任何一个的EditText 字段,然后点击任何按钮,插入一个特定值成非常的EditText 现场他感动。给予使用键盘输入是不允许的。请帮我做这件事。

I have a number of EditTexts in my page along with two buttons. I want the user to touch on any one EditText field and click any button to insert a certain value into that very EditText field he touched. Giving input using keypad is not allowed. Please help me to do this.

推荐答案

有一件事情,你能做的就是声明一个全局变量安勤它会告诉你这是最后一次选择的EditText 通过使用 onTouchListener ,然后根据安勤,您可以通过设置按钮单击文本价值的EditText上。希望你能理解。

One thing that you can do is declare a global variable evalue which will tell you which is the last selected EditText by using onTouchListener and then based on the value of evalue, you can set the text value to the edittext by button click. hope you understood.

在$ C $下它可以如下:

the code for it can be as follow:

EditText e1,e2;
    Button b1,b2;
    String evalue;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        e1=(EditText)findViewById(R.id.editText1);
        e2=(EditText)findViewById(R.id.editText2);
        b1=(Button)findViewById(R.id.button1);
        b2=(Button)findViewById(R.id.button2);

        e1.setOnTouchListener(new View.OnTouchListener()
        {
            public boolean onTouch(View arg0, MotionEvent arg1)
            {
                evalue="1";
                return false;
            }
        });

        e2.setOnTouchListener(new View.OnTouchListener()
        {
            public boolean onTouch(View arg0, MotionEvent arg1)
            {
                evalue="2";
                return false;
            }
        });
        b1.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View arg0) {
                if(evalue=="1")
                {
                    e1.setText("yes");
                }
                if(evalue=="2")
                {
                    e2.setText("yes");
                }
            }
        });


        b2.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View arg0) {
                if(evalue=="1")
                {
                    e1.setText("No");
                }
                if(evalue=="2")
                {
                    e2.setText("No");
                }
            }
        });

    }

其逻辑编码..没有超出该商标。如果你找到一个更好的。然后使用它。谢谢你。

Its a logical coding.. not upto the mark.. if you find a better one. then use it. thank you.

这篇关于如何检测重点的EditText android系统中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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