久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 android 中檢測聚焦的 EditText?

How can I detect focused EditText in android?(如何在 android 中檢測聚焦的 EditText?)
本文介紹了如何在 android 中檢測聚焦的 EditText?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我的頁面中有許多 EditText 元素以及兩個按鈕.我希望用戶觸摸任何一個 EditText 字段并單擊任何按鈕以將某個值插入到他們觸摸的那個 EditText 字段中.不允許使用鍵盤進行輸入.請幫我做這件事.

I have a number of EditText elements 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 they touched. Giving input using the keypad is not allowed. Please help me to do this.

推薦答案

你可以做的一件事是聲明一個全局變量evalue,它會告訴你哪個是最后選擇的EditText通過使用onTouchListener,然后根據evalue的值,可以通過按鈕點擊將文本值設置為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.

代碼如下:

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.

這篇關于如何在 android 中檢測聚焦的 EditText?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Cut, copy, paste in android(在android中剪切、復制、粘貼)
android EditText blends into background(android EditText 融入背景)
Change Line Color of EditText - Android(更改 EditText 的線條顏色 - Android)
EditText showing numbers with 2 decimals at all times(EditText 始終顯示帶 2 位小數的數字)
Changing where cursor starts in an expanded EditText(更改光標在展開的 EditText 中的開始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問題)
主站蜘蛛池模板: 日韩在线免费观看视频 | 亚洲最大的网站 | 在线亚洲天堂 | 一区二区三区不卡视频 | 亚洲久久久 | 亚洲一区二区三区在线播放 | 午夜免费网站 | 欧洲av网站 | 美女久久久久 | www.97超碰 | 亚洲欧美第一页 | 国产又爽又黄免费视频 | 天天看天天射 | 日韩一区三区 | 国产三级视频在线播放 | 亚洲精品三区 | 午夜精品视频在线观看 | 欧美成人一级片 | 欧美色图在线观看 | 熟女毛片| 97色在线 | 国产乱码一区二区三区 | 欧美在线亚洲 | 午夜两性 | 亚洲黄色一级 | 久久久久久亚洲精品 | 国产一级免费观看 | 超碰在线观看免费 | 青青草一区二区 | 福利视频网址 | 欧美精品黄色 | 欧美在线视频观看 | 成人国产精品一区二区 | 三级视频在线观看 | 国产成人99久久亚洲综合精品 | 91亚洲一区 | 一区二区三区在线播放 | 亚洲怡春院 | 日本视频一区二区三区 | 福利在线观看 | 日日爱视频|