开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜