How can I detect focused EditText in android?

前端 未结 8 1054
轮回少年
轮回少年 2020-12-05 06:24

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

8条回答
  •  没有蜡笔的小新
    2020-12-05 07:12

    In your activity or fragment implement OnFocusChangeListener.

    edittextNeme= (EditText) findViewById(R.id.edittextNeme);
    edittextNeme.setOnFocusChangeListener(this);
    

    You will have to check which view changed focus by getting the view id with view.getId() and handle accordingly.

    @Override
    public void onFocusChange(View view, boolean hasfocus) {
        switch(view.getId()){
        case R.id.edittextNeme:
        //Do something
        break;
    
        ...etc
        }
    }
    

提交回复
热议问题