Android的ListView的中心选择 [英] Android ListView center selection
问题描述
我有显示最接近的词一个ListView匹配搜索。
例如,如果我搜索嗨我知道在ListView结果如下
...
您好
喜5
喜五
高
突出
....
我使用
ListView.setSelection(wordList.indexOf(搜索内容));
ListView.setSelected(真);
以上code把所选词喜在顶部和犯规突出的选择。
我想嗨集中定位,选择和自动突出显示。
见下面
...
你好
你好
您好
喜五
喜5
...
什么code,我可以用它来实现上述?
非常感谢。
的ListView视图=(ListView控件)findViewById(R.id.YourListView);INT高度= view.getHeight();
INT itemHeight = view.getChildAt(0).getHeight();
view.setSelectionFromTop(位置,高度/ 2 - itemHeight / 2);
位置(INT)是你想在ListView !!
居中的ListItemI have a ListView that shows the closest word matches to a search.
For example if I search "hi" I get the following results in the ListView
...
hi
hi five
hi-five
high
highlight
....
I am using
ListView.setSelection(wordList.indexOf(searchWord));
ListView.setSelected(true);
The above code puts the selected word "hi" at the top and doesnt highlight the selection.
I want the "hi" to be centrally positioned , selected and highlighted automatically. See below
...
hello
hello there
hi
hi-five
hi five
...
What code can I use to achieve the above?
Many thanks.
ListView view = (ListView)findViewById(R.id.YourListView);
int height = view.getHeight();
int itemHeight = view.getChildAt(0).getHeight();
view.setSelectionFromTop(position, height/2 - itemHeight/2);
The position (int) is the listitem you want to center in the listview!!
这篇关于Android的ListView的中心选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!