如何将 Focuschange Listner 添加到 android 中的 listview
我的一项活动中有一个 listview
。如何设置焦点更改侦听器。我尝试按照代码块进行操作,但没有得到结果。
product_search_list = (ListView) findViewById(R.id.productlist);
product_search_list.setOnFocusChangeListener(onproductchangelistener);
private OnFocusChangeListener onproductchangelistener = new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
int index= (int) ((ListView)v).getSelectedItemId();
Log.i("index",""+index);
}
};
实际上,在列表项的焦点更改时,我想获取焦点列表项的索引并执行必要的操作。
提前致谢。
I am having a listview
in one of my activity. How to set focus change listener. I tried with following the block of code I am not getting a result.
product_search_list = (ListView) findViewById(R.id.productlist);
product_search_list.setOnFocusChangeListener(onproductchangelistener);
private OnFocusChangeListener onproductchangelistener = new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
int index= (int) ((ListView)v).getSelectedItemId();
Log.i("index",""+index);
}
};
Actually, on focus change of list items, I want to get the index of the focused list item and do the necessary operations.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要
setOnItemSelectedListener()
,而不是setOnFocusChangeListener()
。You probably want
setOnItemSelectedListener()
, notsetOnFocusChangeListener()
.