我编写了一个应用程序,其布局中包含一个支持快速滚动的ListView(即拖动滚动条滑块可以让您快速向上或向下滚动列表).这适用于所有版本的Jelly Bean(4.1-4.3).但是,在我更新到Kit Kat后,快速滚动不再有效,我的滚动条只是一个普通的滚动条.但是,如果我退出我的应用程序并重新登录,则会出现快速滚动.如何快速滚动以在Kit Kat中持续工作?我已经复制并粘贴了下面的列表视图适配器代码:
// Adds section popup for fast scroll class NameListAdapter extends SimpleAdapter implements SectionIndexer { HashMapalphaIndexer; private String[] sections; private ArrayList sectionList; private List > data = null; public NameListAdapter (Context context, List > data, int resource, String[] from, int[] to) { super(context, data, resource, from, to); alphaIndexer = new HashMap (); sectionList = new ArrayList (); this.data = data; int size = data.size(); for (int i = 0; i < size; i++) { HashMap myData = (HashMap ) data.get(i); // Get first character String ch = myData.get("name").substring(0, 1); // Convert character to upper case ch = ch.toUpperCase(); // Put first char/index into our HashMap if (!alphaIndexer.containsKey(ch)) { alphaIndexer.put(ch, i); sectionList.add(ch); } } sections = new String[sectionList.size()]; sectionList.toArray(sections); } @Override public int getPositionForSection(int section) { if (section >= sections.length) { return getCount() - 1; } return alphaIndexer.get(sections[section]); } @Override public int getSectionForPosition(int pos) { if (pos > data.size()) { return 0; } HashMap myData = (HashMap ) data.get(pos); String ch = myData.get("name").substring(0, 1); // Convert character to upper case ch = ch.toUpperCase(); for (int i = 0; i < sectionList.size(); i++) { if (sectionList.get(i).equals(ch)) { return i; } } return 0; } @Override public Object[] getSections() { return sections; } }
Talihawk.. 13
这里有同样的问题,这不是一个好的解决方案,但现在你可以这样做:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { view.setFastScrollAlwaysVisible(true); }
这将使您的快速卷轴始终保持开启状态.