簡體   English   中英

有沒有一種方法可以在函數內部調用onClick方法,我應該在參數中傳遞給該方法什么?

[英]is there a way to call onClick method inside a function , what should i pass to the method in the parameters?

我正在從事與計算器應用程序相同的項目,但有4個字段,一個用於計算4個玩家得分的應用程序,還包含一個自定義小鍵盤(數字,運算符,清除和等號按鈕),我不知道如何將按鈕方法應用於4個字段(editText)。...我已經搜索了很多,但找不到任何相關內容

我已經嘗試過使用編輯文本(onFocusChangeListener,onTouchListener),但是主要問題是當我在onFocusChangeListener(我用來確定選擇哪個編輯文本)中調用按鈕方法時,按鈕方法需要一個參數,而我卻沒有不知道我應該傳遞給方法參數什么...。

像這樣

playerTwoScore.setOnFocusChangeListener(new 
View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus){
                   onClick("here is my problem");
            }
        }
    });

我希望當我在第一個編輯文本上使用Tab鍵時,我將能夠單擊按鈕並執行“ 1 + 1 = 2”的操作,而當我在第二個編輯文本上使用選項卡時,我將能夠執行相同的操作

你應該我們TextWatcher

et1.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            // TODO Auto-generated method stub
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {

            // TODO Auto-generated method stub
        }
    });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM