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

如何在 android 中檢測(cè)聚焦的 EditText?

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

問(wèn)題描述

限時(shí)送ChatGPT賬號(hào)..

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

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.

推薦答案

你可以做的一件事是聲明一個(gè)全局變量evalue,它會(huì)告訴你哪個(gè)是最后選擇的EditText通過(guò)使用onTouchListener,然后根據(jù)evalue的值,可以通過(guò)按鈕點(diǎn)擊將文本值設(shè)置為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");
                }
            }
        });

    }

這是一個(gè)邏輯編碼.. 不符合標(biāo)準(zhǔn).. 如果您找到更好的編碼.然后使用它.謝謝.

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

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

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

相關(guān)文檔推薦

Cut, copy, paste in android(在android中剪切、復(fù)制、粘貼)
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 位小數(shù)的數(shù)字)
Changing where cursor starts in an expanded EditText(更改光標(biāo)在展開(kāi)的 EditText 中的開(kāi)始位置)
EditText, adjustPan, ScrollView issue in android(android中的EditText,adjustPan,ScrollView問(wèn)題)
主站蜘蛛池模板: 亚洲精品久久久一区二区三区 | 嫩草视频在线 | 久久久久久国 | 亚洲免费成人 | 亚洲精品一区二区三区四区高清 | 91精品综合久久久久久五月天 | 日韩成人在线视频 | 精品国产伦一区二区三区观看说明 | 久久视频精品 | 日韩精品网站 | 久久久久综合 | 中文字幕日韩欧美一区二区三区 | 国产精品入口麻豆www | 日本不卡视频 | 国产精品久久av | 午夜国产 | 亚洲国产精品一区二区久久 | 91成人免费| 成人蜜桃av| 国产精品久久久久一区二区三区 | 成人免费看片 | 99精品视频在线观看免费播放 | 国产视频一区在线观看 | av网站免费 | 日韩av一区二区在线观看 | 亚洲高清视频一区二区 | 国产精品一区二区三区在线 | 国产一区在线免费 | 天天射天天干 | 亚洲国产小视频 | 一级大片网站 | 99精品欧美一区二区三区 | 91中文在线观看 | 91精品国产一区二区三区 | 亚洲午夜精品在线观看 | 天天操欧美 | 国产在线精品一区二区 | 成人国产精品久久久 | 九色国产 | 欧洲成人免费视频 | 中文字幕一区在线观看视频 |