gpt4 book ai didi

android - ListView OnFocusChangeListener

转载 作者:太空狗 更新时间:2023-10-29 15:15:53 25 4
gpt4 key购买 nike

我在 ListFragment 中有一个 ListView,我想在用户更改列表中的焦点项时更改 fragment 的背景。我特意在这里说焦点,因为这是一个 Google TV 应用程序,所以我针对方向键控件和项目选择做其他事情。

问题是,当列表项焦点发生变化时,如何获得通知或回调,类似于 onListItemClick,但对于焦点?我试过在适配器创建行 View 时在行 View 上设置 OnFocusChangeListener,但似乎从未调用过。

最佳答案

使用 onItemselected 而不是选择ListView中的项目时调用。

listview.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> parent, View view, int position, long id){
//do stuff here
}
});

当用户使用方向控件导航 ListView 时(例如使用方向键在列表中导航时),应使用选定状态。在这种情况下,listView 将处于聚焦状态,其中的 listItems 将处于选中状态。有关状态的更多信息,请参阅 this

关于android - ListView OnFocusChangeListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12861554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com