Android: Evaluate EditText after the user finishes editing

为君一笑 提交于 2019-11-29 08:01:47

I did some research and amongst other things I found this thread. It elaborates upon a similar issue that you're having (of the button not gaining focus). Try the following: On your buttons, set setFocusable(true) (NOT setFocusableInTouchMode! As this spawns the annoying behaviour you stated in your OP), then set the following OnClickListener on your Buttons:

    return new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO workaround because of android issue nr. 2705
            button.requestFocusFromTouch();
            // Do some stuff to handle OnClick
        }
    };

But they should probably just fix the focus stuff for buttons, the current behaviour really does cause some issues (like yours).

Try using both View.setFocusableInTouchMode() and View.requestFocus(). You can use the onKeyListener() interface to detect user input and start a timer after each onKey Event to start your edit after reasonable delay.

what is the problem ur getting? need to include setOnFocusChangeListener with ur editfield. just check it. and have to override the onFocusChange.

plz check for that...

hereenter link description here

Yes there is definitely an issue with edit text not losing the focus once it gains. After quite a bit of googling I found that its possible to achieve the desired result by only workaround.
I had a similar requirement and I made a workaround to accomplish the above task and it works great for me.
The workaround is as follows:
Set the onClickListener for the editText and in the onClick event set a flag saying the editText was clicked.
Set the onKeyListener for the editText and get the current value of the editText in the onKey event.
Now, say you have clicked Done / Back Button in your activity/dialog. Here you can check the flags that got set when the editText was clicked. So if its true make any procedure calls you want.

EditText v = (EditText) layout.findViewById(R.id.framerate);
v.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        Log.d(ExploreUIActivity.TAG, "Insided onClick");
        vClicked= true;
    }
});
v.setOnKeyListener(new OnKeyListener() {
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        Log.d(ExploreUIActivity.TAG, "Inside onKeyListener");
        value = ((EditText) v).getText().toString();
        return false;
    }
});


Now for the back/done button set the onClickListener and check whether the flag was set or not

back.setOnClickListener(new OnClickListener() {
    public onClick(View v) {
        //check the flag
        //if set do some stuff
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!