android:如何设置当我的 ViewFlipper 显示新子项时触发的侦听器
我有一个 ViewFlipper,我希望在显示的子项发生更改时触发侦听器。我已经为 ViewFlipper 设置了一个 OnFocusChangeListener,但当我从子 0 翻转到子 1 时,它永远不会触发,反之亦然。 ViewFlipper 包含两个relativelayout,我尝试为它们设置 OnFocusChangeListeners,但当我尝试设置它时,我得到了 ClassCastException。这是我的代码:
RelativeLayout songsLayout = (RelativeLayout) findViewById(R.id.song_page_layout);
songsLayout.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View view, boolean hasFocus) {
showPopUp("View " + view.getId() + " now has focus: " + hasFocus);
}
} );
R.is.song_page_layout 是我的relativelayout 之一,showPopUp() 是我用来显示弹出窗口的函数。
有没有人有某种触发器的工作代码,当 ViewFlipper 更改显示的子项时会触发该触发器?
I have a ViewFlipper for which I want a listener to fire when the child displayed is changed. I have set an OnFocusChangeListener to the ViewFlipper but it never fires when I flip from child 0 to child 1 or vice-versa. The ViewFlipper contains two RelativeLayouts and I have tried setting OnFocusChangeListeners for those but I get a ClassCastException when I try to set it. Here's my code:
RelativeLayout songsLayout = (RelativeLayout) findViewById(R.id.song_page_layout);
songsLayout.setOnFocusChangeListener(new OnFocusChangeListener() {
public void onFocusChange(View view, boolean hasFocus) {
showPopUp("View " + view.getId() + " now has focus: " + hasFocus);
}
} );
R.is.song_page_layout is one of my RelativeLayouts and showPopUp() is a function I use to show, well, popups.
Does anyone have working code for some sort of trigger that fires when a ViewFlipper changes which child is displayed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你不明白 Android 上的“焦点”是什么意思;当用户选择该视图时,例如,当他们通过按下来选择 EditText,或者使用键盘选择按钮时。当 ViewFlipper 切换视图时,它不会获得或失去焦点。
据我所知,您可以:
不要使用 ViewFlipper 的自动翻转,而是在需要翻转时手动调用 showNext() (然后在代码中自行设置间隔)。
子类化或重新实现 ViewFlipper 并根据您的喜好添加更改侦听器。
子类化或
I think you don't understand what "focus" means on Android; it's when a user selects that View, for example when they select an EditText by pressing on it, or they use the keyboard to select a button. When a ViewFlipper switches Views, it does not gain or lose focus.
As far as I know, you can either:
Don't use ViewFlipper's automatic flipping, instead manually calling showNext() when you want it to flip (then setting the interval yourself in code).
Subclass or reimplement ViewFlipper and add a change listener to your liking.