开发者

How can I find out which view currently has focus? [duplicate]

开发者 https://www.devze.com 2023-03-24 22:48 出处:网络
This question already has answers here: How to find out which view is focused? (6 answers) Closed 6 years ago.
This question already has answers here: How to find out which view is focused? (6 answers) Closed 6 years ago.

My app uses keyboard control and when moving around I've noticed that occasionally you get what I'll refer to as a "Mystery View" - I say that because nothing visible seems to be selected, yet nothing visible is focussed either

Is there any way to find out what I'm focussed on at any given time? eg. a listener that fires on a view selection, etc.

Thanks

** edit - some code for ntc **

LinearLayout col1 = (LinearLayout)findViewById(R.id.col1);
Button btn = new Button(this);
btn.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        LinearLayout col1 = (LinearLayout)findViewById(R.id.col1);
        if(col1.getFocusedChild() != null) {
            Log.d(TAG, col1.g开发者_StackOverflowetFocusedChild().toString());
        }
    }
});
col1.addChild(btn);


getWindow().getCurrentFocus();


You can probably use this method for every view. Maybe this may gets bigger and hectic but is sure to work:

if(yourChildView.isFocused()) {
       yourChildView.setFocusable(false);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消